useSession has an empty user object {}

When using the useSession hook, session.data contains { user: {}, expires: '2023-06-30T20:30:42.181Z' } this is my auth options:
declare module 'next-auth' {
interface Session {
user: {
id: string;
token: string;
};
}
}

export const authOptions: NextAuthOptions = {
pages: {
signIn: '/login',
signOut: '/logout',
},
session: {
strategy: 'jwt',
},
providers: [
CredentialsProvider({
name: 'Credentials',

credentials: {
pincode: { label: 'Pincode', type: 'text', placeholder: '1234567' },
},

async authorize(credentials) {
const pincode = credentials?.pincode;

try {
const {
data: {
user: { id, token },
},
} = await api.post<AuthResponse>(`/auth/login/`, { pincode: pincode });

return {
id: id,
token: token,
};
} catch (error) {
throw new AuthError('Failed to authorize.');
}
},
}),
],
};
declare module 'next-auth' {
interface Session {
user: {
id: string;
token: string;
};
}
}

export const authOptions: NextAuthOptions = {
pages: {
signIn: '/login',
signOut: '/logout',
},
session: {
strategy: 'jwt',
},
providers: [
CredentialsProvider({
name: 'Credentials',

credentials: {
pincode: { label: 'Pincode', type: 'text', placeholder: '1234567' },
},

async authorize(credentials) {
const pincode = credentials?.pincode;

try {
const {
data: {
user: { id, token },
},
} = await api.post<AuthResponse>(`/auth/login/`, { pincode: pincode });

return {
id: id,
token: token,
};
} catch (error) {
throw new AuthError('Failed to authorize.');
}
},
}),
],
};
Aland
Aland352d ago
To be honest i forgot how you exactly add data to the session, but you can check these auth options: https://github.com/AlandSleman/t3-twitter-clone/blob/main/src/pages/api/auth/%5B...nextauth%5D.ts I think if you declare the module you'll get typesafety just like line 29