I have a problem. This is my options file it is located in app/api/auth/[…nextauth]
import GitHubProvider from "next-auth/providers/github";
import GoogleProvider from "next-auth/providers/google";
export const options = {
providers : [
GitHubProvider({
profile(profile){
console.log("Profile Github: ", profile)
let userRole = "Github User"
if(profile?.email == "[email protected]"){
userRole = "Admin"
}
console.log("User Role:>>>>>>>>>>>>>>>> ", userRole)
return {
...profile,
role: userRole
}
},
clientId: process.env.GITHUB_ID,
clientSecret: process.env.GITHUB_SECRET
}),
GoogleProvider({
profile(profile){
console.log("Profile Google: ", profile)
let userRole = "Google User"
return {
...profile,
id: profile.sub,
role: userRole
}
},
clientId: process.env.GOOGLE_ID,
clientSecret: process.env.GOOGLE_SECRET
})
],
callback: {
async jwt({token, user}){
if (user) token.role = user.role
return token
},
async session({session, token}){
if(session?.user) session.user.role = token.role
return session
}
}
}
this is my member page
import { getServerSession } from "next-auth";
import { options } from "../api/auth/[...nextauth]/options";
import { redirect } from "next/navigation";
const Member = async () => {
const session = await getServerSession(options);
if (!session) {
redirect("/api/auth/signin?callbackUrl=/Member");
}
return (
<div>
<h1>Member Server Session</h1>
<p>{session?.user?.email}</p>
<p>{session?.user?.role}</p>
{JSON.stringify(session)}
</div>
);
};
export default Member;
I am using nextjs 14.2.5 and next-auth 4.24.7. I have tried to clear cache (cookies, session & localhost) and restarted the server over and over but still i can not get the user.role what i get is name and email. I need a solution.
Please help
I was expecting to access session?.user?.role but i can not despite of me returning it in the options file