Authentication
Last updated
Last updated
NextAuth intentionally does not allow account auto-linking by default. That means when you sign up first for example with Google and then later on with Facebook (and both accounts use the same email), you get error: "To confirm your identity, sign in with the same account you used originally".
To allow for auto-linking you need to specifically set allowDangerousEmailAccountLinking for each specific provider
Social logins allow users to sign in using their existing accounts from platforms like Google, Facebook, GitHub, and many more.
To enable social login, make sure specific provider is added to next-auth.ts
file, configured with client ID and secret, and callback function profile
mapped to the user model in your database:
.env
file
If you are using Firestore you can add Google authentication through there.
Set in .env
variables:
GOOGLE_ID=
GOOGLE_SECRET=
Remember to whitelist/allow localhost! Otherwise you won't be able to test it locally.
Set .env
variables:
FACEBOOK_APP_ID=
FACEBOOK_SECRET=
Magic link authentication allows users to sign in using a one-time secure link sent to their email, without requiring a password.
Magic links require:
Email provider .env
variables are correctly setup and registered within NextAuth
Setup:
Get the following from your email provider and set these .env
variables:
EMAIL_SERVER_USER=
EMAIL_SERVER_PASSWORD=
EMAIL_SERVER_HOST=
EMAIL_SERVER_PORT=
EMAIL_FROM=
(email account you want to get replies on)
Note: Magic links require database to be setup.
If you are not, you need to create it through Google console:
Create app through developer portal:
to be configured