nextauthjs / nextauthjs/next-auth
Using mssql in auth.ts failed : Module build failed: UnhandledSchemeError: Reading from "node:stream" is not handled by plugins (Unhandled scheme)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 28.4k
- Forks
- 4k
- PR merge metrics
- No merged PRs in 30d
Description
Environment
System:
OS: Linux 5.15 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
CPU: (18) x64 12th Gen Intel(R) Core(TM) i9-12900K
Memory: 43.74 GB / 50.99 GB
Container: Yes
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 22.11.0 - ~/.nvm/versions/node/v22.11.0/bin/node
npm: 10.9.0 - ~/.nvm/versions/node/v22.11.0/bin/npm
bun: 1.0.1 - ~/.bun/bin/bun
npmPackages:
@auth/unstorage-adapter: ^2.0.0 => 2.9.0
next: latest => 14.2.28
next-auth: 5.0.0-beta.26 => 5.0.0-beta.26
react: ^18.2.0 => 18.3.1
Reproduction URL
https://github.com/Mimetis/nextauthjs_google_provider
Describe the issue
Using mssql inside the auth.ts file, especially in the callbacks section (jwt, authorized, ...) does not work.
- trying to open a connection makes the compilation failed (
const pool = new sql.ConnectionPool(setup);) - Opening a connection outside callbacks, in any others file (like any pages) actually works fine
How to reproduce
From any sample, add a callbacks section and try to open a connection to a local reachable SQL server :
import NextAuth from "next-auth";
import "next-auth/jwt";
import sql from "mssql";
import Google from "next-auth/providers/google";
export const { handlers, auth, signIn, signOut } = NextAuth({
debug: !!process.env.AUTH_DEBUG,
providers: [
Google({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
],
session: { strategy: "jwt" },
callbacks: {
authorized({ request, auth }) {
const { pathname } = request.nextUrl;
if (pathname === "/middleware-example") return !!auth;
return true;
},
jwt({ token, trigger, session, account }) {
if (trigger === "update") token.name = session.user.name;
const setup = {
user: process.env.MSSQL_USER,
password: process.env.MSSQL_PASSWORD,
server: process.env.MSSQL_SERVER || "localhost",
database: process.env.MSSQL_DATABASE,
options: {
trustServerCertificate: true, // Set to true if using self-signed certificates
},
};
const pool = new sql.ConnectionPool(setup);
pool.connect().then((c) => {
const request = new sql.Request(c);
c.close();
});
return token;
},
async session({ session, token }) {
if (token?.accessToken) session.accessToken = token.accessToken;
return session;
},
},
experimental: { enableWebAuthn: true },
});
Expected behavior
We should be able to run any server side code as we are supposed to be on server side, as mentioned in the documentation ?
(Extract from the Credentials doc page where we see a direct connection to the database in the example)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the auth.ts reproduction, focusing on the callbacks section where mssql and ConnectionPool are used, then trace the Next.js build failure involving node:stream. Done means the shown server-side database connection compiles and runs without UnhandledSchemeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- next.js, node.js, sql, typescript
- Domain
- authentication, backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100