mxstbr / passport-magic-login

Passwordless authentication with magic links for Passport.js.
MIT License
667 stars 45 forks source link

Send magic link without API call? #35

Open neilrackett opened 1 year ago

neilrackett commented 1 year ago

Thank you for your great work on this strategy!

Is there an existing way to send or generate a magic link using just JavaScript, without needing to do it via a POST/GET call (which the current send() method is specifically designed to do)?

It would be great to be able to send or generate magic links from within a custom API endpoint, for example:

adrianbienias commented 10 months ago

I'd love to have that possibility too. Any chance you found a solution for this?

neilrackett commented 3 months ago

@adrianbienias I've implemented a solution to this by adding a new create method to the MagicLoginStrategy class that returns the same href and code values that are currently passed to your custom sendMagicLink method, for example:

const { href, code } = magicLogin.create('my.email@foo.com');
console.log(`Magic link is ${href} and verification code is ${code}`);

I've created a pull request, but in the meantime you're welcome to use my fork:

npm i github:neilrackett/passport-magic-login
adrianbienias commented 3 months ago

@neilrackett, thanks for sharing your solution. I've also ended up with crafting custom solution (ultimately even using total own implementation instead of passport-magic-login).