✨ feat (pinia): register stores
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
|
||||
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
nuxtApp.$pinia.use(piniaPluginPersistedstate)
|
||||
})
|
||||
@@ -0,0 +1,31 @@
|
||||
export const useUserStore = defineStore(
|
||||
'user',
|
||||
() => {
|
||||
const user = ref<any | null>(null)
|
||||
|
||||
const isAuthenticated = computed(() => !!user.value)
|
||||
const userRole = computed(() => user.value?.user_position_code || '')
|
||||
|
||||
const login = async (userData: any) => {
|
||||
user.value = userData
|
||||
}
|
||||
|
||||
const logout = () => {
|
||||
user.value = null
|
||||
}
|
||||
|
||||
return {
|
||||
user,
|
||||
isAuthenticated,
|
||||
userRole,
|
||||
login,
|
||||
logout,
|
||||
}
|
||||
},
|
||||
{
|
||||
persist: {
|
||||
key: 'user',
|
||||
pick: ['user'],
|
||||
},
|
||||
},
|
||||
)
|
||||
Reference in New Issue
Block a user