Skip to content

Commit a80e71a

Browse files
committed
fix(auth): correct expiration date comparison and format
- Fix logic bug where SQLite date string 'YYYY-MM-DD HH:MM:SS' was being lexicographically compared to ISO string 'YYYY-MM-DDTHH:MM:SS.sssZ', causing premature expiration due to space char < 'T'. - Convert DB dates to proper ISO format before comparison. - Ensure returned expires_at is in strict RFC3339 format for Go client.
1 parent 4d6195d commit a80e71a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/routes/api/auth/cli/poll/+server.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ export const GET: RequestHandler = async ({ platform, url }) => {
1414

1515
if (!row) return json({ status: 'expired' });
1616

17-
if (row.expires_at < new Date().toISOString()) {
17+
// SQLite returns date as "YYYY-MM-DD HH:MM:SS" (UTC)
18+
// We need to convert to ISO format for comparison to avoid string comparison issues
19+
// where "YYYY-MM-DD HH:MM:SS" < "YYYY-MM-DDTHH:MM:SS.sssZ" due to space < T
20+
const expiresAt = new Date(row.expires_at.replace(' ', 'T') + 'Z');
21+
if (expiresAt < new Date()) {
1822
return json({ status: 'expired' });
1923
}
2024

@@ -43,7 +47,8 @@ export const GET: RequestHandler = async ({ platform, url }) => {
4347
status: 'approved',
4448
token: token?.token,
4549
username: user?.username,
46-
expires_at: token?.expires_at
50+
// Ensure strict RFC3339 format for Go client
51+
expires_at: token?.expires_at ? token.expires_at.replace(' ', 'T') + 'Z' : undefined
4752
});
4853
}
4954

0 commit comments

Comments
 (0)