| <!-- src/main/resources/static/home.html --> |
| <!DOCTYPE html> |
| <html lang="zh-CN"> |
| <head><meta charset="UTF-8"><title>首页</title></head> |
| <body> |
| <h1>欢迎访问受保护页面</h1> |
| <div id="userInfo"></div> |
| <script> |
| (async ()=>{ |
| const token = localStorage.getItem('token'); |
| if (!token) return window.location.href='login.html'; |
| const res = await fetch('/api/me', { |
| headers: { 'token': token } |
| }); |
| const json = await res.json(); |
| if (json.code!==0) { |
| return window.location.href='login.html'; |
| } |
| document.getElementById('userInfo') |
| .innerText = '当前用户:' + json.data.username; |
| })(); |
| </script> |
| </body> |
| </html> |