Update tjwt logic to use refresh token

This commit is contained in:
NicolasCantu 2025-05-21 11:58:16 +02:00
parent 0a2a2674f8
commit 0e0c3946d2
3 changed files with 9 additions and 7 deletions

View File

@ -70,7 +70,8 @@ export interface ProcessRetrievedMessage {
export interface ProfileMessage { export interface ProfileMessage {
type: MessageType.CREATE_PROFILE; type: MessageType.CREATE_PROFILE;
data: ProfileData; data: ProfileData;
token: string; accessToken: string;
refreshToken: string;
} }
export interface FolderData { export interface FolderData {

View File

@ -235,7 +235,6 @@ export async function registerAllListeners() {
return; return;
} }
const tokenService = await TokenService.getInstance(); const tokenService = await TokenService.getInstance();
const services = await Services.getInstance();
if (!services.isPaired()) { if (!services.isPaired()) {
const errorMsg = 'Device not paired'; const errorMsg = 'Device not paired';
@ -244,10 +243,10 @@ export async function registerAllListeners() {
} }
try { try {
const { profileData, token } = event.data; const { profileData, accessToken, refreshToken } = event.data;
// Validate the session token // Validate the session token
if (!token || !tokenService.validateToken(token, event.origin)) { if (!accessToken || !tokenService.validateToken(accessToken, event.origin)) {
throw new Error('Invalid or expired session token'); throw new Error('Invalid or expired session token');
} }
@ -257,7 +256,9 @@ export async function registerAllListeners() {
window.parent.postMessage( window.parent.postMessage(
{ {
type: MessageType.PROFILE_CREATED, type: MessageType.PROFILE_CREATED,
token // Resend the same token profileData,
accessToken,
refreshToken
}, },
event.origin event.origin
); );

View File

@ -8,7 +8,7 @@ interface TokenPair {
export default class TokenService { export default class TokenService {
private static instance: TokenService; private static instance: TokenService;
private readonly SECRET_KEY = import.meta.env.VITE_JWT_SECRET_KEY; private readonly SECRET_KEY = import.meta.env.VITE_JWT_SECRET_KEY;
private readonly ACCESS_TOKEN_EXPIRATION = '10s'; private readonly ACCESS_TOKEN_EXPIRATION = '30s';
private readonly REFRESH_TOKEN_EXPIRATION = '7d'; private readonly REFRESH_TOKEN_EXPIRATION = '7d';
private readonly encoder = new TextEncoder(); private readonly encoder = new TextEncoder();