fix: should fix issues with login/session handling

This commit is contained in:
Michael Freno
2026-01-11 20:18:01 -05:00
parent 9cccd0c6b3
commit 99e5323871
3 changed files with 39 additions and 13 deletions

View File

@@ -1214,7 +1214,9 @@ function ActiveSessions(props: { userId: string }) {
}; };
const formatDate = (dateStr: string) => { const formatDate = (dateStr: string) => {
return new Date(dateStr).toLocaleString(undefined, { // Database stores UTC time, convert to local timezone
const date = new Date(dateStr + (dateStr.includes("Z") ? "" : "Z"));
return date.toLocaleString(undefined, {
year: "numeric", year: "numeric",
month: "short", month: "short",
day: "numeric", day: "numeric",
@@ -1266,6 +1268,15 @@ function ActiveSessions(props: { userId: string }) {
<Show when={session.expiresAt}> <Show when={session.expiresAt}>
<div class="text-xs"> <div class="text-xs">
Expires: {formatDate(session.expiresAt)} Expires: {formatDate(session.expiresAt)}
{session.rememberMe !== undefined && (
<span class="text-subtext1 ml-2">
(
{session.rememberMe
? "Remember me"
: "Session-only"}
)
</span>
)}
</div> </div>
</Show> </Show>
</div> </div>

View File

@@ -547,7 +547,12 @@ export default function LoginPage() {
</Show> </Show>
<div class="mx-auto flex pt-4"> <div class="mx-auto flex pt-4">
<input type="checkbox" class="my-auto" ref={rememberMeRef} /> <input
type="checkbox"
class="my-auto"
ref={rememberMeRef}
checked
/>
<div class="my-auto px-2 text-sm font-normal">Remember Me</div> <div class="my-auto px-2 text-sm font-normal">Remember Me</div>
</div> </div>

View File

@@ -430,7 +430,15 @@ export const userRouter = createTRPCRouter({
// Get current session to mark it // Get current session to mark it
const currentSession = await getAuthSession(ctx.event as any); const currentSession = await getAuthSession(ctx.event as any);
return res.rows.map((row: any) => ({ return res.rows.map((row: any) => {
// Infer rememberMe from expires_at duration
// If expires_at is > 2 days from creation, it's a remember-me session
const createdAt = new Date(row.created_at);
const expiresAt = new Date(row.expires_at);
const durationMs = expiresAt.getTime() - createdAt.getTime();
const rememberMe = durationMs > 2 * 24 * 60 * 60 * 1000; // > 2 days
return {
sessionId: row.id, sessionId: row.id,
tokenFamily: row.token_family, tokenFamily: row.token_family,
createdAt: row.created_at, createdAt: row.created_at,
@@ -439,8 +447,10 @@ export const userRouter = createTRPCRouter({
rotationCount: row.rotation_count, rotationCount: row.rotation_count,
clientIp: row.ip_address, clientIp: row.ip_address,
userAgent: row.user_agent, userAgent: row.user_agent,
rememberMe,
isCurrent: currentSession?.sessionId === row.id isCurrent: currentSession?.sessionId === row.id
})); };
});
}), }),
revokeSession: publicProcedure revokeSession: publicProcedure