Session null
Unanswered
Southern rough shrimp posted this in #help-forum
Southern rough shrimpOP
Hi,
When I tried to connect with Discord with Next-auth but session is always undefined after callbackURL.
Informations :
/auth/login
/api/auth/[...nextauth]
When I tried to connect with Discord with Next-auth but session is always undefined after callbackURL.
Informations :
/auth/login
'use client'
import {signIn, signOut, useSession} from "next-auth/react";
import { useRouter } from "next/navigation";
import { Button } from "@/src/components/ui/button";
export default async function LoginPage(){
const session = useSession();
console.log(session);
return (
<button onClick={()=>signIn('discord')} >Se connecter</button>
)
}/api/auth/[...nextauth]
import NextAuth from "next-auth/next";
import DiscordProvider from "next-auth/providers/discord";
import { prisma } from "@/src/config/prisma";
export const authOptions = {
providers:[
DiscordProvider({
clientId: "id",
clientSecret: "secret",
}),
],
callbacks: {
async signIn({user, account, profile, email, credentials}){
console.log({user, account, profile, email, credentials});
const insertDiscord = await prisma.user.upsert({
where:{
discordUsername: `${profile.username}`
},
update:{
},
create:{
discordUsername: `${profile.username}`,
discordAvatar: `${profile.image_url}`,
discordBannerColor: `${profile.banner_color}`
},
select:{
steamid:true
}
});
if(insertDiscord.steamid){
user.steamid = insertDiscord.steamid
}
return true
},
}
};
const handler = NextAuth(authOptions);
export {handler as GET, handler as POST};5 Replies
Southern rough shrimpOP
layout
Provider
import NextAuthProvider from './Provider'
<html lang="en">
<body className={inter.className}>
<NextAuthProvider >{children}</NextAuthProvider>
</body>
</html>Provider
"use client";
import { SessionProvider } from "next-auth/react";
type Props = {
children?: React.ReactNode;
};
export default function NextAuthProvider({ children }: Props){
return <SessionProvider>{children}</SessionProvider>;
};where is callbackURL?
also thats not the main purpose of signIn callback but ok
Southern rough shrimpOP
On discord app, this is my callback url : http://localhost:3000/api/auth/callback/discord
Southern rough shrimpOP
Ok so I'm just stupid, it's logic, I do a console.log but I looked on server console