Mohammad Miras
Mohammad Miras

Reputation: 614

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

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

Upvotes: 0

Views: 3253

Answers (3)

Zoom
Zoom

Reputation: 464

I ran into a very similar problem using @solid-mediakit/auth in SolidStart. The problem is that some requests didn't have the correct basePath in the passed on internal config. Sometimes it would be /api/auth which was my correct auth path, but sometimes this information would be missing, causing it to incorrectly default to /auth.

I guess you could either change your app to always have authentication at /auth. Another solution is to hard code the basePath to your correct auth path (in my case /api/auth):

import DiscordProvider from "@auth/core/providers/discord";
import GithubProvider from "@auth/core/providers/github";
import { SolidAuthConfig } from "@solid-mediakit/auth/";
import { PrismaAdapter } from "@auth/prisma-adapter";
import { PrismaClient } from "@prisma/client";
import { Adapter } from "@auth/core/adapters";

const prisma = new PrismaClient();

export const authOptions: SolidAuthConfig = {
  providers: [
    DiscordProvider({
      clientId: process.env.DISCORD_CLIENT_ID as string,
      clientSecret: process.env.DISCORD_CLIENT_SECRET as string
    }),
    GithubProvider({
      clientId: process.env.GITHUB_CLIENT_ID as string,
      clientSecret: process.env.GITHUB_CLIENT_SECRET as string
    })
  ],
  adapter: PrismaAdapter(prisma) as Adapter,
  basePath: "/api/auth" // <-- Add this line
};

Upvotes: 1

Ahmet Firat Keler
Ahmet Firat Keler

Reputation: 4055

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

Upvotes: 1

Ralphilius
Ralphilius

Reputation: 1856

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

Upvotes: 11

Related Questions