fix: should fix issues with login/session handling
This commit is contained in:
@@ -1214,7 +1214,9 @@ function ActiveSessions(props: { userId: 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",
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
@@ -1266,6 +1268,15 @@ function ActiveSessions(props: { userId: string }) {
|
||||
<Show when={session.expiresAt}>
|
||||
<div class="text-xs">
|
||||
Expires: {formatDate(session.expiresAt)}
|
||||
{session.rememberMe !== undefined && (
|
||||
<span class="text-subtext1 ml-2">
|
||||
(
|
||||
{session.rememberMe
|
||||
? "Remember me"
|
||||
: "Session-only"}
|
||||
)
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</Show>
|
||||
</div>
|
||||
|
||||
@@ -547,7 +547,12 @@ export default function LoginPage() {
|
||||
</Show>
|
||||
|
||||
<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>
|
||||
|
||||
|
||||
@@ -430,17 +430,27 @@ export const userRouter = createTRPCRouter({
|
||||
// Get current session to mark it
|
||||
const currentSession = await getAuthSession(ctx.event as any);
|
||||
|
||||
return res.rows.map((row: any) => ({
|
||||
sessionId: row.id,
|
||||
tokenFamily: row.token_family,
|
||||
createdAt: row.created_at,
|
||||
expiresAt: row.expires_at,
|
||||
lastActiveAt: row.last_active_at,
|
||||
rotationCount: row.rotation_count,
|
||||
clientIp: row.ip_address,
|
||||
userAgent: row.user_agent,
|
||||
isCurrent: currentSession?.sessionId === row.id
|
||||
}));
|
||||
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,
|
||||
tokenFamily: row.token_family,
|
||||
createdAt: row.created_at,
|
||||
expiresAt: row.expires_at,
|
||||
lastActiveAt: row.last_active_at,
|
||||
rotationCount: row.rotation_count,
|
||||
clientIp: row.ip_address,
|
||||
userAgent: row.user_agent,
|
||||
rememberMe,
|
||||
isCurrent: currentSession?.sessionId === row.id
|
||||
};
|
||||
});
|
||||
}),
|
||||
|
||||
revokeSession: publicProcedure
|
||||
|
||||
Reference in New Issue
Block a user