Session type `auth.api.getSession` is wrong

When I do
import { auth } from "@myworkspace/auth";

const { session, user } = (await auth.api.getSession({
headers: fromNodeHeaders(req.headers),
})) ?? { session: null, user: null };
import { auth } from "@myworkspace/auth";

const { session, user } = (await auth.api.getSession({
headers: fromNodeHeaders(req.headers),
})) ?? { session: null, user: null };
the session is typed without activeOrganizationId. When I do
type Session = typeof auth.$Infer.Session;
type Session = typeof auth.$Infer.Session;
in my auth package itself, it's typed properly. I'm already doing
export const auth = betterAuth({
...options,
plugins: [
...(options.plugins ?? []),
customSession(async ({ session, user }, ctx) => {
return {
session,
user,
};
}, options),
],
});
export const auth = betterAuth({
...options,
plugins: [
...(options.plugins ?? []),
customSession(async ({ session, user }, ctx) => {
return {
session,
user,
};
}, options),
],
});
where session is typed as
(parameter) session: {
id: string;
userId: string;
expiresAt: Date;
createdAt: Date;
updatedAt: Date;
token: string;
ipAddress?: string | null | undefined;
userAgent?: string | null | undefined;
} & {
id: string;
userId: string;
expiresAt: Date;
createdAt: Date;
updatedAt: Date;
token: string;
ipAddress?: string | null | undefined;
userAgent?: string | null | undefined;
activeOrganizationId?: string | null | undefined;
}
(parameter) session: {
id: string;
userId: string;
expiresAt: Date;
createdAt: Date;
updatedAt: Date;
token: string;
ipAddress?: string | null | undefined;
userAgent?: string | null | undefined;
} & {
id: string;
userId: string;
expiresAt: Date;
createdAt: Date;
updatedAt: Date;
token: string;
ipAddress?: string | null | undefined;
userAgent?: string | null | undefined;
activeOrganizationId?: string | null | undefined;
}
2 Replies
Amos
AmosOP4w ago
Also getting a lot of other errors related to it I guess:
Property 'getToken' does not exist on type 'InferAPI<{ ok: { <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({ body?: undefined; } & { method?: "GET" | undefined; } & { query?: Record<string, any> | undefined; } & { params?: Record<string, any> | undefined; } & { ...; } & { ...; } & { ...; } & { ...; }) | undefined): ...'.ts(2339)
Property 'getToken' does not exist on type 'InferAPI<{ ok: { <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(inputCtx_0?: ({ body?: undefined; } & { method?: "GET" | undefined; } & { query?: Record<string, any> | undefined; } & { params?: Record<string, any> | undefined; } & { ...; } & { ...; } & { ...; } & { ...; }) | undefined): ...'.ts(2339)
I was on 1.3.4, downgraded to 1.2.8, both have the same problem. Not sure when or why it started happening though
sumanth
sumanth2w ago
I have same type issues with auth.api.getSession but authClient.getSession seams OK

Did you find this page helpful?