11<template >
22 <div >
33 <NuxtErrorBoundary @error =" mHandleError" >
4- <NuxtLayout v-if =" !isPendingAuth || authStore. isAuthenticated" >
4+ <NuxtLayout v-if =" !isMePending || isAuthenticated" >
55 <NuxtPage />
66 </NuxtLayout >
77 </NuxtErrorBoundary >
1010<script setup lang="ts">
1111import { watchEffect } from " vue" ;
1212import { useAuthUser } from " ~/store/auth" ;
13+ import { storeToRefs } from " pinia" ;
1314
1415const authStore = useAuthUser ();
1516
@@ -18,23 +19,21 @@ const route = useRoute();
1819const mHandleError = (e : unknown ) => {
1920 logger .error (" Primary error boundary" , e );
2021};
21- const isPendingAuth = computed (() => authStore . isPending );
22+ const { isAuthenticated, isMePending, authUrl } = storeToRefs ( authStore );
2223// Doing this here instead than in the middleware allow reactivity on the auth user
2324watchEffect (async () => {
24- if (isPendingAuth .value ) {
25+ if (isMePending .value ) {
2526 return ;
2627 }
2728 const shouldRedirectToLogin =
28- ! authStore .isAuthenticated &&
29- authStore .authUrl &&
30- route .name !== " auth-login" ;
29+ ! isAuthenticated .value && authUrl .value && route .fullPath !== authUrl .value ;
3130 if (shouldRedirectToLogin ) {
32- await navigateTo (authStore . authUrl , { external: true });
31+ return navigateTo (authUrl . value , { external: true });
3332 }
3433 const shouldRedirectToHomepage =
35- authStore . isAuthenticated && route .name === " auth-login " ;
34+ isAuthenticated . value && route .fullPath === authUrl . value ;
3635 if (shouldRedirectToHomepage ) {
37- await navigateTo (" /" );
36+ return navigateTo (" /" );
3837 }
3938});
4039 </script >
0 commit comments