Skip to content

Commit a13681d

Browse files
committed
修复CICD
1 parent c3e1919 commit a13681d

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

lib/use-auth.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,21 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
5757
const [status, setStatus] = useState<AuthStatus>("loading");
5858

5959
useEffect(() => {
60-
// 1. 检查 URL 中是否携带 ?token=xxx(后端 OAuth 登录成功后跳回来时携带)
61-
const params = new URLSearchParams(window.location.search);
62-
const urlToken = params.get("token");
60+
// 1. 检查 URL fragment 中是否携带 #token=xxx(后端 OAuth 登录成功后跳回来时携带)
61+
// 使用 fragment 而非 query param:fragment 不会出现在服务器日志和 Referer 头中
62+
const hashParams = new URLSearchParams(window.location.hash.slice(1));
63+
const urlToken = hashParams.get("token");
6364

6465
if (urlToken) {
6566
// 存入 localStorage
6667
localStorage.setItem("satoken", urlToken);
67-
// 用 replaceState 清除 URL 中的 token 参数,避免刷新或分享时 token 泄露
68-
params.delete("token");
69-
const newSearch = params.toString();
68+
// 用 replaceState 清除 URL 中的 fragment,避免刷新或分享时 token 泄露
69+
hashParams.delete("token");
70+
const newHash = hashParams.toString();
7071
const newUrl =
7172
window.location.pathname +
72-
(newSearch ? "?" + newSearch : "") +
73-
window.location.hash;
73+
window.location.search +
74+
(newHash ? "#" + newHash : "");
7475
window.history.replaceState(null, "", newUrl);
7576
}
7677

pnpm-lock.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)