-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-token-refresh.js
More file actions
50 lines (39 loc) · 1.55 KB
/
test-token-refresh.js
File metadata and controls
50 lines (39 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// 简单的token刷新功能测试脚本
// 在浏览器控制台中运行此脚本来测试功能
console.log('🧪 开始测试Token自动刷新功能...');
// 检查服务是否可用
if (typeof window !== 'undefined' && window.tokenRefreshService) {
const service = window.tokenRefreshService;
console.log('✅ Token刷新服务已加载');
// 获取当前状态
const status = service.getRefreshStatus();
console.log('📊 当前状态:', status);
// 测试手动刷新
console.log('🔄 测试手动刷新...');
service.manualRefresh().then(success => {
console.log(success ? '✅ 手动刷新成功' : '❌ 手动刷新失败');
});
// 测试启动服务
console.log('🚀 启动自动刷新服务...');
service.start();
// 5秒后检查状态
setTimeout(() => {
const newStatus = service.getRefreshStatus();
console.log('📊 5秒后状态:', newStatus);
}, 5000);
} else {
console.log('❌ Token刷新服务未找到');
console.log('请确保:');
console.log('1. 页面已完全加载');
console.log('2. 用户已登录');
console.log('3. 服务已正确初始化');
}
// 监听事件测试
window.addEventListener('tokenRefreshed', (event) => {
console.log('🎉 收到token刷新成功事件:', event.detail);
});
window.addEventListener('tokenExpired', (event) => {
console.log('⚠️ 收到token过期事件:', event.detail);
});
console.log('🧪 测试脚本已运行,请查看控制台输出');
console.log('💡 提示:访问 /test-auth 页面可以看到可视化的调试界面');