nextauthjs / next-auth

Authentication for the Web.
https://authjs.dev
ISC License
24.76k stars 3.49k forks source link

Email provider is not working along with middleware #10104

Closed mapaFS closed 8 months ago

mapaFS commented 8 months ago

Provider type

Email

Environment

System: OS: macOS 13.6.1 CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz Memory: 1019.84 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 16.20.1 - ~/.nvm/versions/node/v16.20.1/bin/node Yarn: 1.19.1 - ~/.yarn/bin/yarn npm: 8.19.4 - ~/.nvm/versions/node/v16.20.1/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Browsers: Brave Browser: 76.0.68.132 Chrome: 121.0.6167.184 Edge: 121.0.2277.128 Safari: 17.1 npmPackages: @auth/core: ^0.27.0 => 0.27.0 @auth/prisma-adapter: ^1.4.0 => 1.4.0 next: ^14.1.0 => 14.1.0 next-auth: ^5.0.0-beta.5 => 5.0.0-beta.5 react: ^18.2.0 => 18.2.0

Reproduction URL

https://localhost:3000

Describe the issue

Receiving error when using Email provider along with middleware. Email provider was working fine in next-auth v4. Started breaking during v5-beta upgrade.

Error: The edge runtime does not support Node.js 'stream' module. Learn More: https://nextjs.org/docs/messages/node-module-in-edge-runtime at (webpack-internal:///(middleware)/./node_modules/next/dist/esm/server/web/globals.js:33) at Object.get (webpack-internal:///(middleware)/./node_modules/next/dist/esm/server/web/globals.js:33:19) at eval (webpack-internal:///(middleware)/./node_modules/nodemailer/lib/base64/index.js:43:27) at (middleware)/./node_modules/nodemailer/lib/base64/index.js

Here are my config files:

auth.config.ts import type { NextAuthConfig } from "next-auth";

import GoogleProvider from "next-auth/providers/google"; import Email from "next-auth/providers/email";

export default { providers: [ GoogleProvider({ clientId: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET, }), Email({ server: { host: process.env.EMAIL_SERVER_HOST, port: process.env.EMAIL_SERVER_PORT, auth: { user: process.env.EMAIL_SERVER_USER, pass: process.env.EMAIL_SERVER_PASSWORD, }, }, from: process.env.EMAIL_FROM, }), ], } satisfies NextAuthConfig;

auth.ts

import NextAuth from "next-auth" import { PrismaAdapter } from "@auth/prisma-adapter"; import prisma from "@/lib/prismadb" import authConfig from "@/auth.config";

export const { handlers: { GET, POST }, auth, signIn, signOut, } = NextAuth({ adapter: PrismaAdapter(prisma), pages: { signIn: "/signin", signOut:'/signout' }, session: { strategy: "jwt" }, ...authConfig, });

middleware.ts import NextAuth from "next-auth";

import authConfig from "@/auth.config";

const { auth } = NextAuth(authConfig);

export default auth((req) => { console.log(JSON.stringify(req)); return null; });

// Optionally, don't invoke Middleware on some paths export const config = { matcher: ["/((?!.+\.[\w]+$|_next).)", "/", "/(api|trpc)(.)"], };

How to reproduce

create email adapter as shown in example but with PrismaAdapter; https://authjs.dev/getting-started/providers/email-tutorial

Expected behavior

Magic links / Emails should be sent properly when user tries to sign-in using Email.

github-actions[bot] commented 8 months ago

We could not detect a valid reproduction link. Make sure to follow the bug report template carefully.

Why was this issue closed?

To be able to investigate, we need access to a reproduction to identify what triggered the issue. We need a link to a public GitHub repository. Example: (NextAuth.js example repository).

The bug template that you filled out has a section called "Reproduction URL", which is where you should provide the link to the reproduction.

What should I do?

Depending on the reason the issue was closed, you can do the following:

In general, assume that we should not go through a lengthy onboarding process at your company code only to be able to verify an issue.

My repository is private and cannot make it public

In most cases, a private repo will not be a sufficient minimal reproduction, as this codebase might contain a lot of unrelated parts that would make our investigation take longer. Please do not make it public. Instead, create a new repository using the templates above, adding the relevant code to reproduce the issue. Common things to look out for:

I did not open this issue, but it is relevant to me, what can I do to help?

Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps by opening a new issue.

I think my reproduction is good enough, why aren't you looking into it quickly?

We look into every issue and monitor open issues for new comments.

However, sometimes we might miss a few due to the popularity/high traffic of the repository. We apologize, and kindly ask you to refrain from tagging core maintainers, as that will usually not result in increased priority.

Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.

Useful Resources