Skip to content

Commit 072c597

Browse files
authored
fix(admin): impersonate user session expiration (#1471)
* fix: impersonate user session expiration * console leak
1 parent 9c3b5c3 commit 072c597

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

packages/better-auth/src/api/routes/session.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,21 @@ export const getSession = <Option extends BetterAuthOptions>() =>
3434
* and fetch the session from the database
3535
*/
3636
disableCookieCache: z
37-
.boolean({
38-
description:
39-
"Disable cookie cache and fetch session from database",
40-
})
41-
.or(z.string().transform((v) => v === "true"))
37+
.optional(
38+
z
39+
.boolean({
40+
description:
41+
"Disable cookie cache and fetch session from database",
42+
})
43+
.or(z.string().transform((v) => v === "true")),
44+
)
4245
.optional(),
4346
disableRefresh: z
4447
.boolean({
4548
description:
4649
"Disable session refresh. Useful for checking session status, without updating the session",
4750
})
51+
.or(z.string().transform((v) => v === "true"))
4852
.optional(),
4953
}),
5054
),
@@ -171,7 +175,6 @@ export const getSession = <Option extends BetterAuthOptions>() =>
171175
}
172176
return ctx.json(null);
173177
}
174-
175178
/**
176179
* We don't need to update the session if the user doesn't want to be remembered
177180
* or if the session refresh is disabled

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ export const createInternalAdapter = (
190190
const data: Omit<Session, "id"> = {
191191
ipAddress: request ? getIp(request, ctx.options) || "" : "",
192192
userAgent: headers?.get("user-agent") || "",
193-
...rest,
194193
/**
195194
* If the user doesn't want to be remembered
196195
* set the session to expire in 1 day.
@@ -203,6 +202,7 @@ export const createInternalAdapter = (
203202
token: generateId(32),
204203
createdAt: new Date(),
205204
updatedAt: new Date(),
205+
...rest,
206206
};
207207
const res = await createWithHooks(
208208
data,

0 commit comments

Comments
 (0)