refactor: useAuth / useAuthActions
All checks were successful
Deploy WordPress and Nuxt / deploy (push) Successful in 1m4s

This commit is contained in:
2025-09-18 14:02:00 -04:00
parent 5f23d4094e
commit 6b078267de
7 changed files with 23 additions and 19 deletions

View File

@@ -2,17 +2,21 @@ import type { FormSubmitEvent } from "@nuxt/ui";
export function useAuth() {
const { loggedIn, session } = useUserSession();
const toast = useToast();
const redirect = useRoute().query.redirect as string || "/";
const router = useRouter();
const { fetch: refreshUserSession } = useUserSession();
const isLoggedIn = loggedIn;
const isSwitchedTo = computed(() => Boolean(session.value?.isSwitchedTo));
const hasRole = (role: string) => session.value?.user?.roles?.includes(role) || false;
const isAdmin = computed(() => hasRole("administrator"));
return { isLoggedIn, isSwitchedTo, hasRole, isAdmin };
}
export function useAuthActions() {
const { fetch: refreshUserSession } = useUserSession();
const redirect = useRoute().query.redirect as string || "/";
const router = useRouter();
const toast = useToast();
// Login
const loginFields = [
{
@@ -91,5 +95,5 @@ export function useAuth() {
}
}
return { isLoggedIn, isSwitchedTo, hasRole, isAdmin, loginFields, login, logout, switchTo, switchBack };
return { loginFields, login, logout, switchTo, switchBack };
}