Sync shared components — sidebar scrollbar, Layout, AuthGate updates
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
e0ff800c6b
commit
2c0180ce9a
5 changed files with 163 additions and 7 deletions
|
|
@ -1,10 +1,12 @@
|
|||
import { useEffect, useRef, useState } from 'react'
|
||||
import type { User } from '../types'
|
||||
|
||||
const SHARED_TIMEOUT_MS = 10 * 60 * 1000
|
||||
|
||||
function isSharedDevice() {
|
||||
return document.cookie.split(';').some(c => c.trim() === 'hnf_shared_device=1')
|
||||
function getInactivityMs(): number | undefined {
|
||||
if (window.matchMedia('(display-mode: standalone)').matches) return undefined
|
||||
const c = document.cookie.split(';').map(s => s.trim()).find(s => s.startsWith('hnf_inactivity_mins='))
|
||||
if (!c) return undefined
|
||||
const mins = parseInt(c.split('=')[1])
|
||||
return isNaN(mins) || mins <= 0 ? undefined : mins * 60 * 1000
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -42,7 +44,8 @@ export function AuthGate({ children }: Props) {
|
|||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (state !== 'authed' || !isSharedDevice()) return
|
||||
const ms = getInactivityMs()
|
||||
if (state !== 'authed' || !ms) return
|
||||
|
||||
async function forceLogout() {
|
||||
await fetch('/api/auth/logout', { method: 'POST', credentials: 'include' }).catch(() => {})
|
||||
|
|
@ -52,7 +55,7 @@ export function AuthGate({ children }: Props) {
|
|||
|
||||
function reset() {
|
||||
if (timerRef.current) clearTimeout(timerRef.current)
|
||||
timerRef.current = setTimeout(forceLogout, SHARED_TIMEOUT_MS)
|
||||
timerRef.current = setTimeout(forceLogout, ms)
|
||||
}
|
||||
|
||||
const events = ['mousemove', 'keydown', 'click', 'touchstart'] as const
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue