✨ Refactor JWT utility functions for improved readability and consistency
This commit is contained in:
@@ -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}`;
|
||||
@@ -47,7 +47,7 @@ function createMockJWT() {
|
||||
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());
|
||||
|
||||
Reference in New Issue
Block a user