87 lines
2.3 KiB
TypeScript
87 lines
2.3 KiB
TypeScript
import { computed } from 'vue';
|
|
import { useUserStore } from '@KTXC/stores/userStore';
|
|
|
|
/**
|
|
* Composable for accessing user authentication, profile, and settings
|
|
* Provides a clean API for modules to access user data
|
|
*/
|
|
export function useUser() {
|
|
const store = useUserStore();
|
|
|
|
// =========================================================================
|
|
// Authentication
|
|
// =========================================================================
|
|
|
|
const isAuthenticated = computed(() => store.isAuthenticated);
|
|
const identifier = computed(() => store.identifier);
|
|
const identity = computed(() => store.identity);
|
|
const label = computed(() => store.label);
|
|
const permissions = computed(() => store.permissions);
|
|
|
|
const hasPermission = (permission: string): boolean => {
|
|
return store.permissions.includes(permission);
|
|
};
|
|
|
|
const logout = async (): Promise<void> => {
|
|
await store.logout();
|
|
};
|
|
|
|
// =========================================================================
|
|
// Profile
|
|
// =========================================================================
|
|
|
|
const profile = computed(() => store.profileFields);
|
|
const editableProfile = computed(() => store.editableProfileFields);
|
|
const managedProfile = computed(() => store.managedProfileFields);
|
|
|
|
const getProfile = (key: string): any => {
|
|
return store.getProfileField(key);
|
|
};
|
|
|
|
const setProfile = (key: string, value: any): boolean => {
|
|
return store.setProfileField(key, value);
|
|
};
|
|
|
|
const isProfileEditable = (key: string): boolean => {
|
|
return store.isProfileFieldEditable(key);
|
|
};
|
|
|
|
// =========================================================================
|
|
// Settings
|
|
// =========================================================================
|
|
|
|
const settings = computed(() => store.settings);
|
|
|
|
const getSetting = (key: string): any => {
|
|
return store.getSetting(key);
|
|
};
|
|
|
|
const setSetting = (key: string, value: any): void => {
|
|
store.setSetting(key, value);
|
|
};
|
|
|
|
return {
|
|
// Auth
|
|
isAuthenticated,
|
|
identifier,
|
|
identity,
|
|
label,
|
|
permissions,
|
|
hasPermission,
|
|
logout,
|
|
|
|
// Profile
|
|
profile,
|
|
editableProfile,
|
|
managedProfile,
|
|
getProfile,
|
|
setProfile,
|
|
isProfileEditable,
|
|
|
|
// Settings
|
|
settings,
|
|
getSetting,
|
|
setSetting,
|
|
};
|
|
}
|