-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP-based email provider: type "email"
is not assignable to type "oauth" | "credentials"
#8125
Comments
"email"
is not assignable to type "oauth" | "credentials"
The code itself looks fine, it's just the types that are incorrect. |
I was able to get the code to typecheck by adding the {
id: 'mailgun',
type: 'email',
name: 'Email',
server: null,
options: {},
async sendVerificationRequest({identifier: email, url}) {
// <snip>
}
} |
Actually, the code snippet above only typechecks if I use a local version of The following fails to typecheck: rm -rf node_modules
yarn add next-auth # ^4.22.3 in package.json
yarn install
yarn run build The error it produces: Type error: Type '{ id: string; type: "email"; name: string; server: null; options: {}; 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"'. The following typechecks: rm -rf node_modules
yarn remove next-auth
yarn add path/to/next-auth/packages/next-auth # the repo is checked out to [email protected]
yarn install
yarn run build |
Seems to be broken from this change here: Looking through the ...
import Email from "next-auth/providers/email"
...
// {
// id: 'mailgun',
// type: 'email',
// async sendVerificationRequest({identifier: email, url}) {
// console.log(email)
// }
// },
Email({
type: 'email',
async sendVerificationRequest({identifier: email, url}) {
console.log(email)
}
}),
], 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 |
Really need a fix for this, having the same issue |
Strange, I have to add whole bunch of other properties, to effectively only use the providers: [
{
id: 'email',
type: 'email',
from: '[email protected]',
server: {},
maxAge: 24 * 60 * 60,
name: 'Email',
options: {},
sendVerificationRequest: (params) => {
console.log({ params });
},
},
], The other option seems to be use to he EmailProvider from Is this a TS definitions issue, or something perhaps can we just use EmailProvider, but without requiring Edit: nvm, |
Getting same error too. Hack by @wahidrahim worked fine. |
Still getting this type error with a new install of next/next-auth using T3:
Edit - the workaround above does work, it just requires the |
Why is the const authOptions = {
...,
providers: [
GoogleProvider({...}),
EmailProvider({
server: smtp1,
sendVerificationRequest: async ({ identifier: email, url, provider: { server, from } }) => {...}
}),
EmailProvider({
id: 'invite-member',
name: 'Invite Member',
server: smtp2,
maxAge: 3 * 24 * 60 * 60,
sendVerificationRequest: async ({ identifier: email, url, provider: { server, from } }) => {...}
})
],
...
} satisfies AuthOptions Then elsewhere in code: await signIn('email', {
callbackUrl: `${window.location.origin}/profile`,
email
});
// or
await signIn('invite-member', {
callbackUrl: `${window.location.origin}/auth/new-invite`,
email
}); Each email provider is doing something different. How can I have multiple email providers and call sign-in to each one? |
I created PR #8941 that exposes |
I 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 import NextAuth, { NextAuthOptions } from "next-auth"
import { PrismaAdapter } from "@auth/prisma-adapter"
import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient()
export const authOptions: NextAuthOptions = {
adapter: PrismaAdapter(prisma),
providers: [
{
id: 'sendgrid',
type: 'email',
async sendVerificationRequest({identifier: email, url}) {
// Call the cloud Email provider API for sending emails
// See https://docs.sendgrid.com/api-reference/mail-send/mail-send
const response = await fetch("https://api.sendgrid.com/v3/mail/send", {
// The body format will vary depending on provider, please see their documentation
// for further details.
body: JSON.stringify({
personalizations: [{ to: [{ email }] }],
from: { email: "[email protected]" },
subject: "Sign in to Your page",
content: [
{
type: "text/plain",
value: `Please click here to authenticate - ${url}`,
},
],
}),
headers: {
// Authentication will also vary from provider to provider, please see their docs.
Authorization: `Bearer ${process.env.SENDGRID_API}`,
"Content-Type": "application/json",
},
method: "POST",
})
if (!response.ok) {
const { errors } = await response.json()
throw new Error(JSON.stringify(errors))
}
},
}
],
} And the error is: [auth][error] MissingAdapter: Email login requires an adapter. .Read more at https://errors.authjs.dev#missingadapter
at assertConfig (webpack-internal:///(middleware)/./node_modules/next-auth/node_modules/@auth/core/lib/utils/assert.js:93:34)
at Auth (webpack-internal:///(middleware)/./node_modules/next-auth/node_modules/@auth/core/index.js:82:95 Why is this ticket open for such a long time? |
this worked for me: import EmailProvider from "next-auth/providers/email";
EmailProvider({
async sendVerificationRequest({ identifier: email, url }) {
await sendVerificationRequest({ identifier: email, url });
},
}), |
Ain't ugly if it works! Thanks 🙏 |
Why is this closed? |
Resend example doesn't work too with the same problem - https://authjs.dev/getting-started/providers/resend#configuration |
This comment has been minimized.
This comment has been minimized.
why close, if it is still an issue? |
Provider type
Email
Environment
System:
OS: Linux 6.4 Arch Linux
CPU: (8) x64 11th Gen Intel(R) Core(TM) 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 runningnpm run build
: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.The text was updated successfully, but these errors were encountered: