Skip to content

Commit 6047e54

Browse files
authored
fix: handle potential null values in getCurrentAuthContext (#6327)
1 parent 8429805 commit 6047e54

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/better-auth/src/db/internal-adapter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,13 @@ export const createInternalAdapter = (
264264
override?: (Partial<Session> & Record<string, any>) | undefined,
265265
overrideAll?: boolean | undefined,
266266
) => {
267-
const ctx = await getCurrentAuthContext();
268-
const headers = ctx.headers || ctx.request?.headers;
267+
const ctx = await getCurrentAuthContext().catch(() => null);
268+
const headers = ctx?.headers || ctx?.request?.headers;
269269
const { id: _, ...rest } = override || {};
270270
const data: Omit<Session, "id"> = {
271271
ipAddress:
272-
ctx.request || ctx.headers
273-
? getIp(ctx.request || ctx.headers!, ctx.context.options) || ""
272+
ctx?.request || ctx?.headers
273+
? getIp(ctx?.request || ctx?.headers!, ctx?.context.options) || ""
274274
: "",
275275
userAgent: headers?.get("user-agent") || "",
276276
...rest,

0 commit comments

Comments
 (0)