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 {
type: MessageType.CREATE_PROFILE;
data: ProfileData;
token: string;
accessToken: string;
refreshToken: string;
}
export interface FolderData {

View File

@ -235,7 +235,6 @@ export async function registerAllListeners() {
return;
}
const tokenService = await TokenService.getInstance();
const services = await Services.getInstance();
if (!services.isPaired()) {
const errorMsg = 'Device not paired';
@ -244,20 +243,22 @@ export async function registerAllListeners() {
}
try {
const { profileData, token } = event.data;
const { profileData, accessToken, refreshToken } = event.data;
// 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');
}
// Create profile
await services.createAndSendProfileTx(profileData);
await services.createAndSendProfileTx(profileData);
window.parent.postMessage(
{
type: MessageType.PROFILE_CREATED,
token // Resend the same token
profileData,
accessToken,
refreshToken
},
event.origin
);

View File

@ -8,7 +8,7 @@ interface TokenPair {
export default class TokenService {
private static instance: TokenService;
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 encoder = new TextEncoder();