Need help with next-auth.
Unanswered
Cape lion posted this in #help-forum
Cape lionOP
When i use console.log(session.user) I get that result { user: { name: '....', email: undefined, image: undefined } }
I dont wanna image and email on session. I want id, name and username.
There is my code.
I dont wanna image and email on session. I want id, name and username.
There is my code.
import NextAuth, { NextAuthOptions } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials"
import { mongoConnect } from "@/lib/mongo";
export const authOptions: NextAuthOptions = {
providers: [
CredentialsProvider({
name: "credentials",
credentials: {},
async authorize(credentials, req) {
const { username, password } = credentials
const collection = await mongoConnect()
const check = await collection?.findOne({ username: username })
if (!check) return null;
if (check.password !== password) return null;
const sessionUser = {
id: check.user_id,
name: check.namesurname,
username: check.username,
}
return sessionUser
},
})
],
session: {
strategy: "jwt"
},
pages: {
signIn: "/login",
signOut: "/logout"
}
};
const handler = NextAuth(authOptions);
export { handler as GET, handler as POST };