Error UnknownAction: Cannot parse action at /api/auth/session

1.8k Views Asked by At

I after update package.jsonencountered this error in the project

pacage.json changes enter image description here

I get this error when I run the project:

enter image description here

import { serverAuth$ } from '@builder.io/qwik-auth'
import type { Provider } from '@auth/core/providers'
import Keycloak from '@auth/core/providers/keycloak'

export const { onRequest, useAuthSession, useAuthSignin, useAuthSignout } = serverAuth$(
    ({ env }) => ({
        secret: env.get("AUTH_SECRET"),
        trustHost: true,
        callbacks: {
            async session({
                session,
                token,
            }) {
                session.user.guid = token.sub
                return session
            }
        },
        providers: [
   
        ] as Provider[],
    })
);

2

There are 2 best solutions below

1
Ralphilius On

With [email protected], I get it to work by setting the NEXTAUTH_URL={host}/api/auth

0
Ahmet Firat Keler On

Using some Next.js versions (such as 14.0.3) along with AUTH_URL variable may cause some other types of errors

TypeError: next_dist_server_web_exports_next_request__WEBPACK_IMPORTED_MODULE_0__ is not a constructor

After hours of searching I recommend using packages with the following versions

Next.js and Next-Auth versions

Some people suggests not using AUTH_URL variable, that is going to cause callback url mismatch when you deploy your application

Next Auth: Deployed code redirecting me to localhost on login

If you also have a Dockerfile, do not forget to set env variables in it

ENV AUTH_URL=https://www.yourdomain.com/api/auth