Your Name | 695f6a6 | 2025-05-17 00:58:04 +0800 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <html lang="zh-CN"> |
Your Name | 4fbe811 | 2025-05-20 23:24:17 +0800 | [diff] [blame] | 3 | <head> |
| 4 | <meta charset="UTF-8"> |
| 5 | <title>首页</title> |
| 6 | </head> |
Your Name | 695f6a6 | 2025-05-17 00:58:04 +0800 | [diff] [blame] | 7 | <body> |
| 8 | <h1>欢迎访问受保护页面</h1> |
| 9 | <div id="userInfo"></div> |
| 10 | <script> |
Your Name | 4fbe811 | 2025-05-20 23:24:17 +0800 | [diff] [blame] | 11 | (async () => { |
Your Name | 292c25d | 2025-05-25 01:21:44 +0800 | [diff] [blame] | 12 | const token = localStorage.getItem('token'); |
| 13 | if (!token) { |
| 14 | return window.location.href = 'login.html'; |
Your Name | 695f6a6 | 2025-05-17 00:58:04 +0800 | [diff] [blame] | 15 | } |
Your Name | 292c25d | 2025-05-25 01:21:44 +0800 | [diff] [blame] | 16 | const res = await fetch('/api/me', { |
| 17 | headers: { 'token': token } |
| 18 | }); |
| 19 | const json = await res.json(); |
| 20 | if (json.code !== 0) { |
| 21 | return window.location.href = 'login.html'; |
| 22 | } |
| 23 | document.getElementById('userInfo').innerText = |
| 24 | `当前用户:${json.data.username},Token:${json.data.token}`; |
Your Name | 695f6a6 | 2025-05-17 00:58:04 +0800 | [diff] [blame] | 25 | })(); |
| 26 | </script> |
| 27 | </body> |
Your Name | 292c25d | 2025-05-25 01:21:44 +0800 | [diff] [blame] | 28 | </html> |