blob: 507e3ad4f270fe14a94b2013435de650a65c70be [file] [log] [blame]
Your Name695f6a62025-05-17 00:58:04 +08001<!DOCTYPE html>
2<html lang="zh-CN">
Your Name4fbe8112025-05-20 23:24:17 +08003<head>
4 <meta charset="UTF-8">
5 <title>首页</title>
6</head>
Your Name695f6a62025-05-17 00:58:04 +08007<body>
8<h1>欢迎访问受保护页面</h1>
9<div id="userInfo"></div>
10<script>
Your Name4fbe8112025-05-20 23:24:17 +080011 (async () => {
Your Name292c25d2025-05-25 01:21:44 +080012 const token = localStorage.getItem('token');
13 if (!token) {
14 return window.location.href = 'login.html';
Your Name695f6a62025-05-17 00:58:04 +080015 }
Your Name292c25d2025-05-25 01:21:44 +080016 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 Name695f6a62025-05-17 00:58:04 +080025 })();
26</script>
27</body>
Your Name292c25d2025-05-25 01:21:44 +080028</html>