blob: 507e3ad4f270fe14a94b2013435de650a65c70be [file] [log] [blame]
<!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},Token${json.data.token}`;
})();
</script>
</body>
</html>