mxstbr / passport-magic-login

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

Pass more data at signup #6

Closed matthieuh closed 3 years ago

matthieuh commented 3 years ago

First of all, thank you this package is awesome 😍

I would have one question though: Is it possible to pass more data at signup than just the email address (like a username, language, etc.) or is it an anti-pattern with this way of authenticated a user?

mxstbr commented 3 years ago

I actually had the same question last night. Going to noodle about how to add this!

mxstbr commented 3 years ago

As of 1.0.6 you can POST any payload you want!

fetch(`/auth/magiclogin`, {
  method: `POST`,
  body: JSON.stringify({
    // `destination` is required.
    destination: email,
    // You can POST anything else in your payload...
    name: name,
  }),
  headers: { 'Content-Type': 'application/json' }
})

And then you can access it in verify! :tada:

const magicLogin = new MagicLoginStrategy({
  // "payload" contains "destination" and anything else you POST'ed
  verify: (payload, callback) => {
    console.log(payload.name)
  }
})
matthieuh commented 3 years ago

That's awesome thank you 🙏