fix: refresh returning 401 not properly logging you out of client

This commit is contained in:
SauceyRed 2025-05-28 02:24:54 +02:00
parent 6a11108ec1
commit a15f85a082
Signed by: sauceyred
GPG key ID: 2BF92EB6D8A5CCA7
2 changed files with 79 additions and 70 deletions

View file

@ -30,11 +30,11 @@ export const useAuth = () => {
{
username, password: hashedPass, device_name: "Linux Laptop"
}
}) as { access_token: string, refresh_token: string }; fetch
}) as { access_token: string, refresh_token: string };
console.log("hi");
accessToken.value = res.access_token;
console.log("access token:", accessToken.value);
await fetchUser();
//await fetchUser();
}
async function logout(password: string) {
@ -60,19 +60,17 @@ export const useAuth = () => {
async function refresh() {
console.log("refreshing");
try {
const res = await fetchWithApi("/auth/refresh", {
method: "POST"
}) as { access_token: string };
accessToken.value = res.access_token;
console.log("set new access token");
} catch (error) {
console.error("refresh error:", error);
}
const res = await fetchWithApi("/auth/refresh", {
method: "POST"
}) as any;
console.log("finished refreshing:", res);
accessToken.value = res?.access_token;
console.log("set new access token");
}
async function fetchUser() {
if (!accessToken.value) return;
console.log("fetchuser access token:", accessToken.value);
const res = await fetchWithApi("/users/me") as UserResponse;
user.value = res;
return user.value;