add basic user authentication
This commit is contained in:
21
front/src/auth.store.js
Normal file
21
front/src/auth.store.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
export const useAuthStore = defineStore('auth', {
|
||||
state: () => ({
|
||||
// initialize state from local storage to enable user to stay logged in
|
||||
user: JSON.parse(localStorage.getItem('user')),
|
||||
returnUrl: null
|
||||
}),
|
||||
actions: {
|
||||
login(user) {
|
||||
this.user = user;
|
||||
localStorage.setItem('user', JSON.stringify(user));
|
||||
},
|
||||
logout() {
|
||||
this.user = null;
|
||||
localStorage.removeItem('user');
|
||||
useRouter().push('/');
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user