Update tjwt logic to use refresh token
This commit is contained in:
parent
0a2a2674f8
commit
0e0c3946d2
@ -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 {
|
||||
|
@ -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
|
||||
);
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user