#29 refactor: replace admin code with role-based auth using Pinia
This commit is contained in:
19
src/stores/auth.js
Normal file
19
src/stores/auth.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useAuthStore = defineStore('auth', {
|
||||
state: () => ({
|
||||
user: null
|
||||
}),
|
||||
getters: {
|
||||
isAdmin: (state) => state.user?.role === 'administrator',
|
||||
isAuthenticated: (state) => !!state.user
|
||||
},
|
||||
actions: {
|
||||
setUser(user) {
|
||||
this.user = user
|
||||
},
|
||||
clearUser() {
|
||||
this.user = null
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user