add basic user authentication

This commit is contained in:
2025-10-01 21:43:37 +02:00
parent 57355fe9ac
commit f20e177480
16 changed files with 338 additions and 51 deletions

21
front/src/auth.store.js Normal file
View 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('/');
}
}
});