Next.js Discord

Discord Forum

NextAuth not saving session

Unanswered
Shawty posted this in #help-forum
Open in Discord
I am logging in through discord but after login and callback, the session is still undefined.

check:
const {data: session} = useSession();
    if(!session) return <AccessDenied/>;


src/pages/api/auth/[...nextauth].ts:
// pages/api/auth/[...nextauth].ts
import NextAuth from 'next-auth';
import Discord from "next-auth/providers/discord";
import {CLIENT_ID, CLIENT_SECRET} from "../../../../Constants";

export default NextAuth({
    providers: [
        Discord({
            clientId: CLIENT_ID,
            clientSecret: CLIENT_SECRET,
            authorization: {params: {scope: 'identify guilds', prompt: 'none'}}
        }),
    ],
    secret: "moodyisalwaysthebest",
    callbacks: {
        async signIn() {
            // Access user, account, and profile using params object

            return '/dashboard'; // Allow sign-in
        },
       
        async redirect(params) {
            // Access url and baseUrl using params object
            const {url, baseUrl} = params;

            return url.startsWith(baseUrl) ? url : baseUrl;
        },

    },

    pages: {
        error: '/error',
        signIn: '/signin'

    },
});

1 Reply

video reference: