fix: infinite redirect issue (#583)

This commit is contained in:
Hayden 2023-10-10 08:43:44 -05:00 committed by GitHub
parent d8482f3a13
commit ae4b95301f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View file

@ -3,14 +3,18 @@ export default defineNuxtRouteMiddleware(async () => {
const api = useUserApi();
if (!ctx.isAuthorized()) {
return navigateTo("/");
if (window.location.pathname !== "/") {
return navigateTo("/");
}
}
if (!ctx.user) {
console.log("Fetching user data");
const { data, error } = await api.user.self();
if (error) {
return navigateTo("/");
if (window.location.pathname !== "/") {
return navigateTo("/");
}
}
ctx.user = data.item;