mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
43 lines
900 B
TypeScript
43 lines
900 B
TypeScript
import type { AuthContext } from "~/server/middleware/01-authorization";
|
|
|
|
|
|
const loggedUser = ref<AuthContext | undefined>();
|
|
|
|
const setLoggedUser = (authContext?: AuthContext) => {
|
|
loggedUser.value = authContext;
|
|
};
|
|
|
|
const isLogged = computed(() => {
|
|
return loggedUser.value?.logged;
|
|
})
|
|
|
|
const isAdmin = computed(() => {
|
|
if (!loggedUser.value?.logged) return false;
|
|
return loggedUser.value.user.roles.includes('ADMIN');
|
|
});
|
|
|
|
const isPremium = computed(() => {
|
|
if (!loggedUser.value?.logged) return false;
|
|
return loggedUser.value.user.roles.includes('PREMIUM');
|
|
});
|
|
|
|
function getUserRoles() {
|
|
return { isAdmin, isPremium }
|
|
}
|
|
|
|
export const isAdminHidden = ref<boolean>(false);
|
|
|
|
export function useLoggedUser() {
|
|
return {
|
|
isLogged,
|
|
isPremium,
|
|
isAdmin,
|
|
user: loggedUser,
|
|
userRoles: getUserRoles(),
|
|
setLoggedUser
|
|
}
|
|
}
|
|
|
|
|
|
|