Skip to content

Using mssql in auth.ts failed : Module build failed: UnhandledSchemeError: Reading from "node:stream" is not handled by plugins (Unhandled scheme) #12923

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

Open
Mimetis opened this issue Apr 29, 2025 · 0 comments
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

Comments

@Mimetis
Copy link

Mimetis commented Apr 29, 2025

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 },
});

Image

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)

Image

@Mimetis Mimetis added bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Projects
None yet
Development

No branches or pull requests

1 participant