feat: implement session restoration using /api/user/me
This commit is contained in:
@@ -92,11 +92,19 @@ export const useAuthStore = defineStore("auth", () => {
|
||||
}
|
||||
|
||||
async function checkAuth() {
|
||||
isLoading.value = true;
|
||||
if (token.value) {
|
||||
if (user.value) {
|
||||
try {
|
||||
apiClient.defaults.headers.common["Authorization"] = `Bearer ${token.value}`;
|
||||
const response = await apiClient.get("/api/user/me");
|
||||
user.value = response.data;
|
||||
await fetchUserProfile();
|
||||
} catch (e) {
|
||||
console.error("Session restoration failed:", e);
|
||||
handleLogout();
|
||||
}
|
||||
}
|
||||
isLoading.value = false;
|
||||
}
|
||||
return {
|
||||
// State
|
||||
|
||||
Reference in New Issue
Block a user