next-auth: HTTP-based email provider: type `"email"` is not assignable to type `"oauth" | "credentials"`
Provider type
Environment
System: OS: Linux 6.4 Arch Linux CPU: (8) x64 11th Gen Intel® Core™ i7-1185G7 @ 3.00GHz Memory: 26.16 GB / 31.06 GB Container: Yes Shell: 5.9 - /usr/bin/zsh Binaries: Node: 20.4.0 - /usr/bin/node Yarn: 3.3.0 - /usr/bin/yarn npm: 9.8.1 - /usr/bin/npm pnpm: 8.6.10 - /usr/bin/pnpm
Reproduction URL
https://github.com/mcevoypeter/next-auth-issue-repro
Describe the issue
I’m attempting to configure an HTTP-based email provider following the guide from the docs. When I add a stubbed-out provider object to the providers
object key, I get the following error when running npm run build
:
> build
> next build
- info Linting and checking validity of types ...Failed to compile.
./pages/api/auth/[...nextauth].ts:35:5
Type error: Type '{ id: string; type: "email"; sendVerificationRequest({ identifier: email, url }: { identifier: any; url: any; }): Promise<void>; }' is not assignable to type 'Provider'.
Types of property 'type' are incompatible.
Type '"email"' is not assignable to type '"oauth" | "credentials"'.
33 | version: "2.0",
34 | }),
> 35 | {
| ^
36 | id: 'mailgun',
37 | type: 'email',
38 | async sendVerificationRequest({identifier: email, url}) {
How to reproduce
git clone https://github.com/mcevoypeter/next-auth-issue-repro
cd next-auth-issue-repro
npm install
npm run build
Expected behavior
I expect npm run build
to cleanly compile.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 6
- Comments: 15 (2 by maintainers)
Why is this closed? It looks like is still an issue in next-auth 5.0.0-beta.13 This does not work: https://authjs.dev/guides/providers/email-http
Strange, I have to add whole bunch of other properties, to effectively only use the
sendVerificationRequest
methodThe other option seems to be use to he EmailProvider from
next-auth/providers/email
but that requires installingnodemailer
, which is not necessary at all for my needs; I am using a separate service for sending emails to users.Is this a TS definitions issue, or something perhaps can we just use EmailProvider, but without requiring
nodemailer
somehow (this seems best)?Edit: nvm,
nodemailer
is not required. Seems I can get around by just usingsendVerificationRequest
directlyI am using “next-auth”: “5.0.0-beta.5”, and I still have the same issue: TS2322: Type ‘“email”’ is not assignable to type ‘“oidc” | “credentials” | “oauth”’.
And I literally use the example from the documentation: https://authjs.dev/guides/providers/email-http#setup
And the error is:
Why is this ticket open for such a long time?
Seems to be broken from this change here: https://github.com/nextauthjs/next-auth/commit/1e886b97bcd76b0679a00d6d03e9cc0a68ca9407
Looking through the
next-auth
code, it seems like the intended fix should be:It seems the current Email provider doesn’t allow overwriting the id field however, which seems problematic.
Can you chime in on what changes should happen @balazsorban44? Seems like we could update the docs to use the provider, and just add in
id?: = "email"
to theEmailUserConfig
.this worked for me:
I was able to get the code to typecheck by adding the
name
,server
, andoptions
keys: