Next.js Discord

Discord Forum

Cannot parse action at /api/auth/session

Answered
Catla posted this in #help-forum
Open in Discord
CatlaOP
Using Auth v5, and receiving this error:

[auth][error] UnknownAction: Cannot parse action at /api/auth/session .Read more at https://errors.authjs.dev#unknownaction
    at parseActionAndProviderId (webpack-internal:///(rsc)/./node_modules/@auth/core/lib/utils/web.js:87:27)
    at toInternalRequest (webpack-internal:///(rsc)/./node_modules/@auth/core/lib/utils/web.js:32:40)
    at Auth (webpack-internal:///(rsc)/./node_modules/@auth/core/index.js:82:103)
    at httpHandler (webpack-internal:///(rsc)/./node_modules/next-auth/index.js:73:80)
    at eval (webpack-internal:///(rsc)/./node_modules/next/dist/esm/server/future/route-modules/app-route/module.js:220:43)
    at eval (webpack-internal:///(rsc)/./node_modules/next/dist/esm/server/lib/trace/tracer.js:96:36)
    at NoopContextManager.with (webpack-internal:///(rsc)/./node_modules/next/dist/compiled/@opentelemetry/api/index.js:361:30)
    at ContextAPI.with (webpack-internal:///(rsc)/./node_modules/next/dist/compiled/@opentelemetry/api/index.js:31:58)
    at NoopTracer.startActiveSpan (webpack-internal:///(rsc)/./node_modules/next/dist/compiled/@opentelemetry/api/index.js:954:34)
    at ProxyTracer.startActiveSpan (webpack-internal:///(rsc)/./node_modules/next/dist/compiled/@opentelemetry/api/index.js:994:36)


It happens the moment I enter the website.

I'm totally stumped, the docs don't help too much, and I wouldn't even know what pieces of my code I need to share to debug this.
Answered by Catla
I resolved the issue. I'm not exactly sure what I did, but I recall:
Making sure my NEXTAUTH_URL was correct in my .env
Removing my export const runtime = "edge";
View full answer

14 Replies

CatlaOP
Heres my auth.ts:

import prisma from "@/db";
import NextAuth from "next-auth";
import authConfig from "./auth.config";

export const { handlers: { GET, POST }, auth } = NextAuth({
    pages: {
        signIn: '/'
    },
    session: {
        strategy: "jwt",
        maxAge: 2 * 24 * 60 * 60
    },
    callbacks: {
        async session({ session, token }) {
            session.user.id = token.sub;

            return session;
        },
        async signIn({ user, account, profile }) {
            if (account?.provider === "discord" && profile) {
                user.image = profile.avatar ? `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.png` : `https://cdn.discordapp.com/embed/avatars/${Math.abs(Number(profile.id) >> 22) % 5}.png`

                return true;
            } else if (account?.provider === "roblox" && user) {
                const session = await auth();

                const existingAccount = await prisma.accounts.findUnique({
                    where: {
                        id: user.id as string,
                    },
                });

                if (existingAccount) return '/manage/accounts';

                const accounts = await prisma.accounts.findMany({
                    where: {
                        ownerId: session?.user.id
                    },
                })

                const isPrimary = accounts.length === 0;

                await prisma.accounts.create({
                    data: {
                        id: user.id as string,
                        ownerId: session?.user.id,
                        isPrimary: isPrimary
                    }
                })

                return '/manage/accounts';
            };

            return '/';
        },
    },
    ...authConfig
});
And heres my auth.config.ts:

import DiscordProvider from "next-auth/providers/discord";
import { RobloxProvider } from "roblox-provider";

import type { NextAuthConfig } from "next-auth"

export default {
    providers: [
        DiscordProvider({
            clientId: process.env.DISCORD_CLIENT_ID as string,
            clientSecret: process.env.DISCORD_CLIENT_SECRET as string,
            authorization: { params: { scope: 'identify guilds' } },
        }),
        RobloxProvider({
            clientId: process.env.ROBLOX_ID as string,
            clientSecret: process.env.ROBLOX_SECRET as string,
            redirectUri: 'https://rolinker.net/auth',
            scopes: ["openid"],
        })
    ],
} satisfies NextAuthConfig
Heres my api/auth/[...nextauth]/route.ts:

export { GET, POST } from "@/auth";
export const runtime = "edge";
Note that auth.config.ts and auth.ts are both inside my src directory.
I do not use any middleware.
American
did you solve this problem?
CatlaOP
No
I just posted it
this is a known next-auth v5-beta.6+ bug
@joulev this is a known next-auth v5-beta.6+ bug
CatlaOP
I am using 5.0.0-beta.2
Should I upgrade to beta 5?
@Catla Should I upgrade to beta 5?
hmm try beta 5 then, because beta 5 (or beta 4) is known to not have this bug
CatlaOP
I resolved the issue. I'm not exactly sure what I did, but I recall:
Making sure my NEXTAUTH_URL was correct in my .env
Removing my export const runtime = "edge";
Answer