Skip to content

Commit d8d497c

Browse files
feat(provider): call generateVerificationToken async (#1378)
1 parent 6152c8a commit d8d497c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/server/lib/signin/email.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default async function email (email, provider, options) {
1010
const secret = provider.secret || options.secret
1111

1212
// Generate token
13-
const token = provider.generateVerificationToken?.() ?? randomBytes(32).toString('hex')
13+
const token = await provider.generateVerificationToken?.() ?? randomBytes(32).toString('hex')
1414

1515
// Send email with link containing token (the unhashed version)
1616
const url = `${baseUrl}${basePath}/callback/${encodeURIComponent(provider.id)}?email=${encodeURIComponent(email)}&token=${encodeURIComponent(token)}`

www/docs/providers/email.md

+14
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,17 @@ const text = ({ url, site }) => `Sign in to ${site}\n${url}\n\n`
184184
:::tip
185185
If you want to generate great looking email client compatible HTML with React, check out https://mjml.io
186186
:::
187+
188+
189+
## Customising the Verification Token
190+
191+
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:
192+
193+
```js title="pages/api/auth/[...nextauth].js"
194+
providers: [
195+
Providers.Email({
196+
async generateVerificationToken() {
197+
return "ABC123"
198+
}
199+
})
200+
],

0 commit comments

Comments
 (0)