detached 334edb8

feat(session): Simplify session renewal logic for online status

- Remove session expiry threshold check
- Always renew session when user status is online
- Streamline session token generation and cookie setting
commit
334edb852234054287e1f546d01b169b97d61d4c
author
Kit · · 2025-02-19 06:47 UTC
parent
0b43029
signature
SSH UnverifiedSHA256:H91DFuEG4jpk5edzLA4aUKkpv4zv9Q339ipRmkph6Tk The key is unknown
1 file · +8 -12
M src/routes/api/status/+server.ts +8 -12
@@ -47,23 +47,19 @@ export const POST: RequestHandler = async ({ request, cookies, locals }) => {
4747 .get();
4848 log.debug('Database updated successfully', { userId: maskedUserId, status });
4949
50- // Renew session if status is online and session is near expiry
50+ // Renew session if status is online
5151 if (status === 'online') {
5252 const token = cookies.get('session');
5353 if (token) {
5454 const result = await validateSessionToken(token);
5555 if (result.session) {
56- const remaining = result.session.expiresAt - now;
57- const threshold = 15 * 60 * 1000; // 15 minutes in milliseconds
58- if (remaining < threshold) {
59- const newToken = generateSessionToken();
60- const newSession = await createSession(newToken, userId);
61- setSessionTokenCookie({ cookies }, newToken, newSession.expiresAt);
62- log.info('Session renewed', {
63- userId: maskedUserId,
64- expiresAt: new Date(newSession.expiresAt).toISOString()
65- });
66- }
56+ const newToken = generateSessionToken();
57+ const newSession = await createSession(newToken, userId);
58+ setSessionTokenCookie({ cookies }, newToken, newSession.expiresAt);
59+ log.info('Session renewed', {
60+ userId: maskedUserId,
61+ expiresAt: new Date(newSession.expiresAt).toISOString()
62+ });
6763 }
6864 }
6965 }
@@ -47,23 +47,19 @@ export const POST: RequestHandler = async ({ request, cookies, locals }) => {
47 .get();47 .get();
48 log.debug('Database updated successfully', { userId: maskedUserId, status });48 log.debug('Database updated successfully', { userId: maskedUserId, status });
49 49
50- // Renew session if status is online and session is near expiry50+ // Renew session if status is online
51 if (status === 'online') {51 if (status === 'online') {
52 const token = cookies.get('session');52 const token = cookies.get('session');
53 if (token) {53 if (token) {
54 const result = await validateSessionToken(token);54 const result = await validateSessionToken(token);
55 if (result.session) {55 if (result.session) {
56- const remaining = result.session.expiresAt - now;56+ const newToken = generateSessionToken();
57- const threshold = 15 * 60 * 1000; // 15 minutes in milliseconds57+ const newSession = await createSession(newToken, userId);
58- if (remaining < threshold) {58+ setSessionTokenCookie({ cookies }, newToken, newSession.expiresAt);
59- const newToken = generateSessionToken();59+ log.info('Session renewed', {
60- const newSession = await createSession(newToken, userId);60+ userId: maskedUserId,
61- setSessionTokenCookie({ cookies }, newToken, newSession.expiresAt);61+ expiresAt: new Date(newSession.expiresAt).toISOString()
62- log.info('Session renewed', { 62+ });
63- userId: maskedUserId,
64- expiresAt: new Date(newSession.expiresAt).toISOString()
65- });
66- }
67 }63 }
68 }64 }
69 }65 }

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 3

Tags 8

↑↓ moveenter openesc close