38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
// Utility to test authentication persistence
|
|
export const testAuthPersistence = () => {
|
|
console.log('=== Testing Authentication Persistence ===');
|
|
|
|
// Check localStorage
|
|
const accessToken = localStorage.getItem('accessToken');
|
|
const refreshToken = localStorage.getItem('refreshToken');
|
|
const sessionId = localStorage.getItem('sessionId');
|
|
|
|
console.log('localStorage tokens:');
|
|
console.log('- accessToken:', accessToken ? 'Present' : 'Missing');
|
|
console.log('- refreshToken:', refreshToken ? 'Present' : 'Missing');
|
|
console.log('- sessionId:', sessionId ? 'Present' : 'Missing');
|
|
|
|
// Check if tokens are valid (not expired)
|
|
if (accessToken) {
|
|
try {
|
|
const payload = JSON.parse(atob(accessToken.split('.')[1]));
|
|
const expiry = new Date(payload.exp * 1000);
|
|
const now = new Date();
|
|
|
|
console.log('Token expiry:', expiry.toISOString());
|
|
console.log('Current time:', now.toISOString());
|
|
console.log('Token expired:', expiry < now);
|
|
} catch (error) {
|
|
console.log('Error parsing token:', error);
|
|
}
|
|
}
|
|
|
|
console.log('==========================================');
|
|
};
|
|
|
|
// Function to simulate page reload
|
|
export const simulatePageReload = () => {
|
|
console.log('Simulating page reload...');
|
|
// Clear any in-memory state but keep localStorage
|
|
window.location.reload();
|
|
};
|