From ac0a31c071f0f1a19f7df98f25c78f8718640645 Mon Sep 17 00:00:00 2001 From: FragginWagon Date: Wed, 28 Jan 2026 22:46:07 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Refactor=20JWT=20utility=20function?= =?UTF-8?q?s=20for=20improved=20readability=20and=20consistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pokedex.online/server/utils/jwt-utils.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/code/websites/pokedex.online/server/utils/jwt-utils.js b/code/websites/pokedex.online/server/utils/jwt-utils.js index 416895a..a74be45 100644 --- a/code/websites/pokedex.online/server/utils/jwt-utils.js +++ b/code/websites/pokedex.online/server/utils/jwt-utils.js @@ -24,9 +24,9 @@ function createMockJWT() { return { sign: (payload, secret, options) => { // Mock JWT: base64(header).base64(payload).base64(signature) - const header = Buffer.from(JSON.stringify({ alg: 'HS256', typ: 'JWT' })).toString( - 'base64' - ); + const header = Buffer.from( + JSON.stringify({ alg: 'HS256', typ: 'JWT' }) + ).toString('base64'); const body = Buffer.from(JSON.stringify(payload)).toString('base64'); const signature = Buffer.from('mock-signature').toString('base64'); return `${header}.${body}.${signature}`; @@ -36,18 +36,18 @@ function createMockJWT() { const parts = token.split('.'); if (parts.length !== 3) throw new Error('Invalid token format'); const payload = JSON.parse(Buffer.from(parts[1], 'base64').toString()); - + // Check expiration if (payload.exp && Date.now() >= payload.exp * 1000) { throw new Error('Token expired'); } - + return payload; } catch (err) { throw new Error(`Invalid token: ${err.message}`); } }, - decode: (token) => { + decode: token => { const parts = token.split('.'); if (parts.length !== 3) return null; return JSON.parse(Buffer.from(parts[1], 'base64').toString()); @@ -64,7 +64,7 @@ function createMockJWT() { */ export function createToken(payload, secret, expiresIn = 7 * 24 * 60 * 60) { const now = Math.floor(Date.now() / 1000); - + return jwt.sign( { ...payload,