Skip to content

Commit

Permalink
feat(provider): call generateVerificationToken async (#1378)
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsorban44 committed Feb 27, 2021
1 parent 6152c8a commit d8d497c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/server/lib/signin/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default async function email (email, provider, options) {
const secret = provider.secret || options.secret

// Generate token
const token = provider.generateVerificationToken?.() ?? randomBytes(32).toString('hex')
const token = await provider.generateVerificationToken?.() ?? randomBytes(32).toString('hex')

// Send email with link containing token (the unhashed version)
const url = `${baseUrl}${basePath}/callback/${encodeURIComponent(provider.id)}?email=${encodeURIComponent(email)}&token=${encodeURIComponent(token)}`
Expand Down
14 changes: 14 additions & 0 deletions www/docs/providers/email.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,17 @@ const text = ({ url, site }) => `Sign in to ${site}\n${url}\n\n`
:::tip
If you want to generate great looking email client compatible HTML with React, check out https://mjml.io
:::


## Customising the Verification Token

By default, we are generating a random verification token. You can define a `generateVerificationToken` method in your provider options if you want to override it:

```js title="pages/api/auth/[...nextauth].js"
providers: [
Providers.Email({
async generateVerificationToken() {
return "ABC123"
}
})
],

1 comment on commit d8d497c

@vercel
Copy link

@vercel vercel bot commented on d8d497c Feb 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.