// Set up a store to track auth state
const defaultAuthState: SupabaseAuthData = {
isAuthenticated: false,
isLoading: true,
supabaseSession: null,
isAdmin: false,
};
const [authStore, setAuthStore] = createStore(defaultAuthState);
const { data: { subscription }, } = supabase.auth.onAuthStateChange(async (_event, session) => {
// Check to see if there is a session.
if (!!session) {
// A session exists. Update the auth store
setAuthStore({ isAuthenticated: true, supabaseSession: session, isAdmin: adminUser });
console.log(authStore.isAuthenticated); // result true
console.log(location.pathname.includes("/auth"); // result true
// NOT WORKING
if (location.pathname.includes("/auth") && authStore.isAuthenticated) {
navigate(`/${appRoute}`, { replace: true });
}
}
});
// Set up a store to track auth state
const defaultAuthState: SupabaseAuthData = {
isAuthenticated: false,
isLoading: true,
supabaseSession: null,
isAdmin: false,
};
const [authStore, setAuthStore] = createStore(defaultAuthState);
const { data: { subscription }, } = supabase.auth.onAuthStateChange(async (_event, session) => {
// Check to see if there is a session.
if (!!session) {
// A session exists. Update the auth store
setAuthStore({ isAuthenticated: true, supabaseSession: session, isAdmin: adminUser });
console.log(authStore.isAuthenticated); // result true
console.log(location.pathname.includes("/auth"); // result true
// NOT WORKING
if (location.pathname.includes("/auth") && authStore.isAuthenticated) {
navigate(`/${appRoute}`, { replace: true });
}
}
});