useSession has an empty user object {}

Nniels5/31/2023
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.');
}
},
}),
],
};
AAland5/31/2023
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

Looking for more? Join the community!