#JWEDecryptionFailed

1 messages · Page 1 of 1 (latest)

warm gate
#

I'm currently writing playwright tests for my application. When trying to set up the authentification for the tests I get following error for the tests, when I route through the application I get nothing, all works fine for me there:

[auth][details]: {}
[auth][error] JWTSessionError: Read more at https://errors.authjs.dev#jwtsessionerror
[auth][cause]: JWEDecryptionFailed: decryption operation failed
    at gcmDecrypt (webpack-internal:///(rsc)/./node_modules/jose/dist/node/esm/runtime/decrypt.js:81:15)
    at decrypt (webpack-internal:///(rsc)/./node_modules/jose/dist/node/esm/runtime/decrypt.js:104:20)
    at flattenedDecrypt (webpack-internal:///(rsc)/./node_modules/jose/dist/node/esm/jwe/flattened/decrypt.js:139:90)
    at async compactDecrypt (webpack-internal:///(rsc)/./node_modules/jose/dist/node/esm/jwe/compact/decrypt.js:22:23)
    at async jwtDecrypt (webpack-internal:///(rsc)/./node_modules/jose/dist/node/esm/jwt/decrypt.js:12:23)
    at async Object.decode (webpack-internal:///(rsc)/./node_modules/next-auth/node_modules/@auth/core/jwt.js:68:25)
    at async Module.session (webpack-internal:///(rsc)/./node_modules/next-auth/node_modules/@auth/core/lib/actions/session.js:23:29)
    at async AuthInternal (webpack-internal:///(rsc)/./node_modules/next-auth/node_modules/@auth/core/lib/index.js:50:24)
    at async Auth (webpack-internal:///(rsc)/./node_modules/next-auth/node_modules/@auth/core/index.js:123:29)
    at async AuthInfo (webpack-internal:///(rsc)/./src/app/auth-info/page.tsx:11:21)

In layout.tsx there only ``{children}` And my middleware looks like this

import { auth } from "auth";

export default auth;

export const config = { matcher: ["/recipe/create", "/recipe/:id/edit"] };
lethal cedarBOT
#

Hi @warm gate. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Hmm, I don't know enough to give you a confident answer yet. The error message you're seeing, JWEDecryptionFailed: decryption operation failed, suggests that there's an issue with decrypting a JSON Web Token (JWT) in your application. However, the information extracts provided do not contain specific details about handling JWT decryption errors in Next.js or the auth module you're using in your middleware.

It might be helpful to check the documentation of the auth module you're using, or the Next.js documentation (https://nextjs.org/docs) for more information on handling authentication and potential errors.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@warm gate kapa.ai is still learning and improving, please let us know how it did by reacting below

warm gate
#

@lethal cedar My auth.ts looks like:

export const {
  handlers: { GET, POST },
  auth,
} = NextAuth({
  session: {
    strategy: "jwt",
  },
  providers: [Discord],
  adapter: PrismaAdapter(db),
  pages: {
    signIn: "/auth/signin",
    signOut: "/auth/signout",
  },
  callbacks: {
    authorized(params) {
      return !!params.auth?.user;
    },
    jwt: async (data) => {
      return data.token;
    },
    session: async ({ session, user, token }) => {
      // @ts-expect-error
      session.user.id = token.sub;
      console.log(token);
      return session;
    },
  },
  cookies: {
    pkceCodeVerifier: {
      name: "next-auth.pkce.code_verifier",
      options: {
        httpOnly: true,
        sameSite: "none",
        path: "/",
        secure: true,
      },
    },
  },
  // @ts-expect-error
}) satisfies NextAuthConfig;
lethal cedarBOT
#

Let me check the knowledge base for you. One moment! :books:

#

From the provided extracts, it's not clear what specific issue you're facing with your auth.ts configuration. However, I can provide some general insights based on the code you've shared.

Your auth.ts file is configuring NextAuth.js with a JWT session strategy, Discord as the authentication provider, and Prisma as the adapter. You've also defined custom callbacks for authorized, jwt, and session.

If you're facing issues with this setup, it could be due to a variety of reasons, such as misconfiguration of the provider or adapter, issues with the JWT session strategy, or problems with the custom callbacks.

Here are a few things you could check:

  1. Provider Configuration: Ensure that the Discord provider is correctly configured. This typically involves setting up a Discord application and obtaining a client ID and secret.

  2. Adapter Configuration: Make sure that the Prisma adapter is correctly set up. This involves setting up a Prisma schema and generating Prisma client.

  3. JWT Session Strategy: If you're using the JWT session strategy, ensure that the JWT signing key is correctly configured.

  4. Callbacks: Check the logic in your custom callbacks. For example, in the session callback, you're assigning token.sub to session.user.id. Ensure that token.sub is correctly populated and that it's the value you want to assign to session.user.id.

If you're still facing issues, it would be helpful to provide more specific details about the problem you're encountering.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: