Type mismatch between auth.api.getSession and typeof user.$inferSelect

I have a backend server with express and drizzle. I get the type of the userTable with typeof user.$inferSelect This type is different from the type of session.user that returns from auth.api.getSession.
export type SelectUser = typeof user.$inferSelect;
type SelectUser = {
id: string;
name: string;
email: string;
emailVerified: boolean;
image: string | null;
createdAt: Date;
updatedAt: Date;
role: string | null;
banned: boolean | null;
banReason: string | null;
banExpires: Date | null;
usid: string | null;
}
export type SelectUser = typeof user.$inferSelect;
type SelectUser = {
id: string;
name: string;
email: string;
emailVerified: boolean;
image: string | null;
createdAt: Date;
updatedAt: Date;
role: string | null;
banned: boolean | null;
banReason: string | null;
banExpires: Date | null;
usid: string | null;
}
export const createContext = async (opts: CreateExpressContextOptions) => {
const session = await auth.api.getSession({
headers: fromNodeHeaders(opts.req.headers)
});
const user = session?.user
};
const user: {
id: string;
email: string;
emailVerified: boolean;
name: string;
createdAt: Date;
updatedAt: Date;
image: string | null | undefined;
banned: boolean | null | undefined;
role: string | null | undefined;
banReason: string | null | undefined;
banExpires: Date | null | undefined;
usid: string | null | undefined;
} | undefined
export const createContext = async (opts: CreateExpressContextOptions) => {
const session = await auth.api.getSession({
headers: fromNodeHeaders(opts.req.headers)
});
const user = session?.user
};
const user: {
id: string;
email: string;
emailVerified: boolean;
name: string;
createdAt: Date;
updatedAt: Date;
image: string | null | undefined;
banned: boolean | null | undefined;
role: string | null | undefined;
banReason: string | null | undefined;
banExpires: Date | null | undefined;
usid: string | null | undefined;
} | undefined
Is there a way to remove the undefined from the type getSession().user?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?