To create a next-auth secret key, run the following command:

npx auth secret

This will generate a secret key that you can use in your .env file.

NEXTAUTH_SECRET=YOUR_SECRET_KEY

Also update the NEXTAUTH_URL in your .env file to match your domain. Replace http://localhost:3000 with your domain if you are deploying to production.

NEXTAUTH_URL=http://localhost:3000

Google OAuth

To enable Google OAuth, you need to create a new project in the Google Developer Console.

  1. Go to the Google Developer Console.

  2. Create a new project.

  3. Go to the OAuth consent screen and fill in the required fields.

  4. Go to the Credentials tab and create a new OAuth client ID.

  5. Add the client ID and client secret to your .env file.

AUTH_GOOGLE_ID=YOUR_GOOGLE_CLIENT_ID
AUTH_GOOGLE_SECRET=YOUR_GOOGLE_CLIENT_SECRET

To enable Magic Link, you need a email provider. We are using Resend in this Boilerplate.

  1. Go to Resend and create an account.

  2. Go to the Settings tab and copy the API key.

  3. Add the API key to your .env file.

AUTH_RESEND_KEY=YOUR_RESEND_API

You also need to add your domain to the Resend Domains.

Now for the functionality to work, you need to add the following code to your config/config.ts file and set also the additionalAuthMethod to magic-link. You get the infos from the Resend SMTP page.

You can also change this to your own SMTP provider.

...
email: {
  server: {
    host: 'smtp.resend.com',
    port: 587,
    auth: {
      user: // Your Resend Username,
      pass: // Your Resend API key,
    },
  },
  from: // Your sending email address,
},
...

Was this page helpful?