fix: jwt token exposed in url

This commit is contained in:
Timothy Jaeryang Baek
2025-08-06 21:02:54 +04:00
parent 041da26756
commit 0912a023c2
2 changed files with 12 additions and 10 deletions

View File

@@ -101,18 +101,19 @@
};
const checkOauthCallback = async () => {
if (!$page.url.hash) {
return;
// Get the value of the 'token' cookie
function getCookie(name) {
const match = document.cookie.match(
new RegExp('(?:^|; )' + name.replace(/([.$?*|{}()[\]\\/+^])/g, '\\$1') + '=([^;]*)')
);
return match ? decodeURIComponent(match[1]) : null;
}
const hash = $page.url.hash.substring(1);
if (!hash) {
return;
}
const params = new URLSearchParams(hash);
const token = params.get('token');
const token = getCookie('token');
if (!token) {
return;
}
const sessionUser = await getSessionUser(token).catch((error) => {
toast.error(`${error}`);
return null;
@@ -120,6 +121,7 @@
if (!sessionUser) {
return;
}
localStorage.token = token;
await setSessionUser(sessionUser);
};