Closed newme616 closed 9 months ago
I've also been having next-auth issues and just made #133 documenting mine, maybe ours are similar?
I have the same issue. I don't think EmailProvider supports edge, which makes this implementation challenging because tmk, middleware.ts
must be run in edge.
An example using EmailProvider
in this repo would be great to see.
Facing the exact same issue using "next-auth": "5.0.0-beta.3"
⨯ ./node_modules/nodemailer/lib/base64/index.js:3:18
Module not found: Can't resolve 'stream'
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
./node_modules/nodemailer/lib/mime-node/index.js
./node_modules/nodemailer/lib/mail-composer/index.js
./node_modules/nodemailer/lib/mailer/index.js
./node_modules/nodemailer/lib/nodemailer.js
./node_modules/@auth/core/providers/email.js
./node_modules/next-auth/providers/email.js
is there a fix for this?
@mundia416 see https://github.com/vercel-labs/ai-chatbot/issues/133 for hack-around solution. Not ideal, but I believe you can get it to work by using the mentioned manual next-auth release.
Does email work at all with this?
When I add
import EmailProvider from "next-auth/providers/email";
to auth.ts and
EmailProvider({
server: process.env.EMAIL_SERVER,
from: process.env.EMAIL_FROM
}),
To the providers, I get
Type 'EmailConfig' is not assignable to type 'Provider'.
Type 'EmailConfig' is not assignable to type 'EmailConfig & InternalProviderOptions'.
Type 'EmailConfig' is not assignable to type 'InternalProviderOptions'.
Types of property 'options' are incompatible.
Type 'EmailUserConfig' is not assignable to type 'Record<string, unknown>'.
Index signature for type 'string' is missing in type 'EmailUserConfig'.
Ran into this issue too. What a shame.
Let's continue this conversation on the NextAuth.js repo – this template won't be adding nodemailer, and sounds like a more general question around integrating those two together. Thank you.
@maddo7 It seems like a typing issue only, so you can force the typing.
EmailProvider({
server: process.env.EMAIL_SERVER,
from: process.env.EMAIL_FROM
}) as EmailConfig & { options: Record<string, unknown> },
As a (temporary) solution, you can render everything server side instead of on edge.
middleware.ts
.Find and remove the following line in all files in the app
directory:
export const runtime = 'edge'
@leerob Can you link to the topic on the nextauth.js repo where this is discussed?
Same issue here. Did anybody solve it with nodemailer?
Server Error Error: The edge runtime does not support Node.js 'stream' module.
For what its worth I made it work by implementing an HTTP based email provider: https://next-auth.js.org/tutorials/securing-pages-and-api-routes
my providers:
providers: [
Discord,
Google({
clientId: env.AUTH_GOOGLE_CLIENT_ID,
clientSecret: env.AUTH_GOOGLE_CLIENT_SECRET,
}),
Facebook({
clientId: env.AUTH_FACEBOOK_CLIENT_ID,
clientSecret: env.AUTH_FACEBOOK_CLIENT_SECRET,
}),
{
id: "sendgrid",
type: "email",
async sendVerificationRequest({identifier: email, url}) {
// your code here to send the email
},
},
],
Then the middleware worked
As a (temporary) solution, you can render everything server side instead of on edge.
- Remove
middleware.ts
.- Find and remove the following line in all files in the
app
directory:export const runtime = 'edge'
@leerob Can you link to the topic on the nextauth.js repo where this is discussed?
how would you protect routes if there is no middleware provided
I fixed this by having two auth configurations, one for auth-client and another for auth-server. The configurations that are critical to the server, like EmailProvider, are put into auth-server. which makes sense; those details are sensitive and should not be exposed to the client. You need to then go to all pages (like the api folder, etc.) that need server-side auth verification and point to auth-server. In my case both auth-server and auth-client look the same except the EmailProvider and possibly other configurations.
For what its worth I made it work by implementing an HTTP based email provider: https://next-auth.js.org/tutorials/securing-pages-and-api-routes
my providers:
providers: [ Discord, Google({ clientId: env.AUTH_GOOGLE_CLIENT_ID, clientSecret: env.AUTH_GOOGLE_CLIENT_SECRET, }), Facebook({ clientId: env.AUTH_FACEBOOK_CLIENT_ID, clientSecret: env.AUTH_FACEBOOK_CLIENT_SECRET, }), { id: "sendgrid", type: "email", async sendVerificationRequest({identifier: email, url}) { // your code here to send the email }, }, ],
Then the middleware worked
pixelcatgg, did you end up making it work with an HTTP based email provider? I get Type '"email"' is not assignable to type '"credentials" | "oidc" | "oauth"'.ts(2322)
Nodemailer seems to be not compatible with edge?
I get this error if I try to implement Email Provider in auth.ts.
Error:
Code:
package.json