Browse Source
1. 新增工具函数处理URL鉴权token清理 2. 使用location.replace替代reload避免重复提交 3. 在全局认证提供者中自动清理URL中的token参数feature/interaction
3 changed files with 30 additions and 1 deletions
@ -0,0 +1,25 @@ |
|||||
|
"use client"; |
||||
|
|
||||
|
const AUTH_TOKEN_QUERY_KEY = "token"; |
||||
|
|
||||
|
export function removeAuthTokenFromCurrentUrl(): string | null { |
||||
|
if (typeof window === "undefined") return null; |
||||
|
|
||||
|
const url = new URL(window.location.href); |
||||
|
if (!url.searchParams.has(AUTH_TOKEN_QUERY_KEY)) { |
||||
|
return `${url.pathname}${url.search}${url.hash}`; |
||||
|
} |
||||
|
|
||||
|
url.searchParams.delete(AUTH_TOKEN_QUERY_KEY); |
||||
|
const cleanedUrl = `${url.pathname}${url.search}${url.hash}`; |
||||
|
window.history.replaceState(window.history.state, "", cleanedUrl); |
||||
|
return cleanedUrl; |
||||
|
} |
||||
|
|
||||
|
export function getCurrentUrlWithoutAuthToken(): string { |
||||
|
if (typeof window === "undefined") return "/"; |
||||
|
|
||||
|
const url = new URL(window.location.href); |
||||
|
url.searchParams.delete(AUTH_TOKEN_QUERY_KEY); |
||||
|
return `${url.pathname}${url.search}${url.hash}` || "/"; |
||||
|
} |
||||
Loading…
Reference in new issue