Add effect to clean oauth query params
cgen-36c4185356a549c696420f6b1e40717a
This commit is contained in:
parent
c1f011e450
commit
0303c996a3
1 changed files with 38 additions and 0 deletions
|
|
@ -106,6 +106,44 @@ export default function Dashboard() {
|
||||||
}
|
}
|
||||||
}, [searchParams, activeTab]);
|
}, [searchParams, activeTab]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (typeof window === "undefined" || !user) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const currentUrl = new URL(window.location.href);
|
||||||
|
const preservedTab = currentUrl.searchParams.get("tab");
|
||||||
|
const keysToStrip = [
|
||||||
|
"code",
|
||||||
|
"state",
|
||||||
|
"scope",
|
||||||
|
"auth_error",
|
||||||
|
"error_description",
|
||||||
|
"access_token",
|
||||||
|
"refresh_token",
|
||||||
|
"token_type",
|
||||||
|
"provider",
|
||||||
|
"type",
|
||||||
|
];
|
||||||
|
let mutated = false;
|
||||||
|
keysToStrip.forEach((key) => {
|
||||||
|
if (currentUrl.searchParams.has(key)) {
|
||||||
|
currentUrl.searchParams.delete(key);
|
||||||
|
mutated = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (mutated) {
|
||||||
|
if (preservedTab) {
|
||||||
|
currentUrl.searchParams.set("tab", preservedTab);
|
||||||
|
} else {
|
||||||
|
currentUrl.searchParams.delete("tab");
|
||||||
|
}
|
||||||
|
const nextSearch = currentUrl.searchParams.toString();
|
||||||
|
const nextUrl = `${currentUrl.pathname}${nextSearch ? `?${nextSearch}` : ""}${currentUrl.hash}`;
|
||||||
|
window.history.replaceState(null, "", nextUrl);
|
||||||
|
}
|
||||||
|
}, [user]);
|
||||||
|
|
||||||
const handleTabChange = (value: string) => {
|
const handleTabChange = (value: string) => {
|
||||||
setActiveTab(value);
|
setActiveTab(value);
|
||||||
const next = new URLSearchParams(searchParams);
|
const next = new URLSearchParams(searchParams);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue