This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

semble / src / webapp / lib / auth / token.ts
721 B 27 lines
1export const isTokenExpiringSoon = ( 2 token: string | null | undefined, 3): boolean => { 4 if (!token) return true; 5 6 const bufferSeconds = parseInt( 7 process.env.NEXT_PUBLIC_ACCESS_TOKEN_EXPIRY_BUFFER_SECONDS || '300', 8 10, 9 ); 10 11 try { 12 // Validate JWT structure first 13 const parts = token.split('.'); 14 if (parts.length !== 3) return true; 15 16 const payload = JSON.parse(Buffer.from(parts[1], 'base64').toString()); 17 18 // Ensure exp claim exists and is a number 19 if (!payload.exp || typeof payload.exp !== 'number') return true; 20 21 const expiry = payload.exp * 1000; 22 const bufferTime = bufferSeconds * 1000; 23 return Date.now() >= expiry - bufferTime; 24 } catch { 25 return true; 26 } 27};