feat(auth): refactor authentication routes and enhance JWT handling
Build and Push Auth Portal Docker Image / build-and-push (push) Successful in 1m49s
Build and Push Auth Portal Docker Image / create-release (push) Skipped

- Removed unused permission and app retrieval logic from the login process.
- Introduced a new endpoint for reissuing access tokens to handle role changes and account switches.
- Updated JWT payload handling to improve clarity and maintainability.
- Enhanced the readJwtPayload function for better decoding of JWT claims.
This commit is contained in:
Denozordec
2026-07-19 02:22:23 +07:00
parent ed1699503a
commit 09ed7f4dc4
9 changed files with 206 additions and 84 deletions
+10 -4
View File
@@ -199,19 +199,25 @@ function isPrivateHostname(hostname: string): boolean {
return false
}
/** Decode JWT `exp` without verifying signature. Returns null if missing/invalid. */
export function readJwtExp(token: string): number | null {
/** Decode JWT payload without verifying signature (claims sync only). */
export function readJwtPayload(token: string): Record<string, unknown> | null {
try {
const parts = token.split('.')
if (parts.length < 2) return null
const json = atob(parts[1]!.replace(/-/g, '+').replace(/_/g, '/'))
const payload = JSON.parse(json) as { exp?: unknown }
return typeof payload.exp === 'number' ? payload.exp : null
return JSON.parse(json) as Record<string, unknown>
} catch {
return null
}
}
/** Decode JWT `exp` without verifying signature. Returns null if missing/invalid. */
export function readJwtExp(token: string): number | null {
const payload = readJwtPayload(token)
if (!payload) return null
return typeof payload.exp === 'number' ? payload.exp : null
}
/** True when token is missing exp or exp is in the past (30s clock-skew grace). */
export function isJwtExpired(token: string, nowMs: number = Date.now()): boolean {
const exp = readJwtExp(token)