LinkDesk/frontend/clear-tokens.html

176 lines
6.0 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Clear Expired Tokens</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
max-width: 600px;
margin: 50px auto;
padding: 20px;
background: #f5f5f5;
}
.container {
background: white;
border-radius: 8px;
padding: 30px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
h1 {
color: #1a365d;
margin-bottom: 10px;
}
.warning {
background: #fef3c7;
border: 2px solid #f59e0b;
border-radius: 6px;
padding: 15px;
margin: 20px 0;
color: #92400e;
}
.success {
background: #d1fae5;
border: 2px solid #10b981;
border-radius: 6px;
padding: 15px;
margin: 20px 0;
color: #065f46;
}
button {
background: #3b82f6;
color: white;
border: none;
padding: 12px 24px;
border-radius: 6px;
font-size: 16px;
cursor: pointer;
font-weight: 500;
}
button:hover {
background: #2563eb;
}
button:disabled {
background: #9ca3af;
cursor: not-allowed;
}
.info {
background: #eff6ff;
border: 2px solid #3b82f6;
border-radius: 6px;
padding: 15px;
margin: 20px 0;
color: #1e40af;
}
.token-info {
font-family: monospace;
font-size: 12px;
background: #f3f4f6;
padding: 10px;
border-radius: 4px;
margin: 10px 0;
word-break: break-all;
}
</style>
</head>
<body>
<div class="container">
<h1>🔐 Clear Expired Tokens</h1>
<div class="warning">
<strong>⚠️ Token Expiration Issue</strong><br>
Your JWT tokens have expired. This is causing the "Signature has expired" error when trying to log in.
</div>
<div id="tokenStatus" class="info">
<strong>Current Token Status:</strong>
<div id="tokenDetails"></div>
</div>
<button id="clearBtn" onclick="clearTokens()">Clear Expired Tokens</button>
<div id="result" style="display: none;"></div>
<div class="info" style="margin-top: 30px;">
<strong>What this does:</strong><br>
• Removes access_token from localStorage<br>
• Removes refresh_token from localStorage<br>
• Allows you to log in fresh with valid credentials
</div>
<div class="info">
<strong>After clearing tokens:</strong><br>
1. Click the "Clear Expired Tokens" button above<br>
2. Navigate to <a href="http://localhost:5173/login">http://localhost:5173/login</a><br>
3. Log in with your credentials<br>
4. You should now be able to access the application
</div>
</div>
<script>
function checkTokens() {
const accessToken = localStorage.getItem('access_token');
const refreshToken = localStorage.getItem('refresh_token');
const detailsDiv = document.getElementById('tokenDetails');
if (!accessToken && !refreshToken) {
detailsDiv.innerHTML = '<div class="token-info">✅ No tokens found - you can log in fresh!</div>';
document.getElementById('clearBtn').disabled = true;
document.getElementById('clearBtn').textContent = 'No Tokens to Clear';
} else {
let html = '';
if (accessToken) {
try {
const payload = JSON.parse(atob(accessToken.split('.')[1]));
const exp = new Date(payload.exp * 1000);
const now = new Date();
const expired = exp < now;
html += `<div class="token-info">
<strong>Access Token:</strong> ${expired ? '❌ EXPIRED' : '✅ Valid'}<br>
Expires: ${exp.toLocaleString()}<br>
${expired ? `Expired ${Math.floor((now - exp) / (1000 * 60 * 60 * 24))} days ago` : ''}
</div>`;
} catch (e) {
html += '<div class="token-info">❌ Access Token: Invalid format</div>';
}
}
if (refreshToken) {
html += '<div class="token-info">🔄 Refresh Token: Present (likely expired)</div>';
}
detailsDiv.innerHTML = html;
}
}
function clearTokens() {
const accessToken = localStorage.getItem('access_token');
const refreshToken = localStorage.getItem('refresh_token');
if (!accessToken && !refreshToken) {
showResult('No tokens to clear!', 'info');
return;
}
localStorage.removeItem('access_token');
localStorage.removeItem('refresh_token');
showResult('✅ Tokens cleared successfully! You can now log in fresh.', 'success');
setTimeout(() => {
checkTokens();
}, 500);
}
function showResult(message, type) {
const resultDiv = document.getElementById('result');
resultDiv.className = type;
resultDiv.innerHTML = message;
resultDiv.style.display = 'block';
}
// Check tokens on page load
checkTokens();
</script>
</body>
</html>