first commit

This commit is contained in:
Adrian Zürcher
2025-10-12 14:56:18 +02:00
parent a9f2e11fe6
commit a908db4f38
92 changed files with 13273 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
import { defineStore } from 'pinia';
import { useGlobalRouter } from 'src/utils/globalRouter';
import { useGlobalQ } from 'src/utils/globalQ';
interface User {
username: string;
role: string;
}
interface UserState {
user: User | null;
}
export const useUserStore = defineStore('user', {
state: (): UserState => ({
user: null,
}),
getters: {
isAuthenticated: (state): boolean => !!state.user,
},
actions: {
setUser(user: User) {
this.user = user;
},
getUser() {
return this.user;
},
clearUser() {
const $q = useGlobalQ();
if (!this.user) return;
if ($q) {
$q?.notify({
message: "user '" + this.user?.username + "' logged out",
color: 'orange',
position: 'bottom-right',
icon: 'warning',
timeout: 5000,
});
} else {
console.error("user '" + this.user?.username + "' logged out");
}
this.user = null;
const router = useGlobalRouter();
router?.push('/').catch((err) => {
if ($q) {
$q?.notify({
message: err,
color: 'orange',
position: 'bottom-right',
icon: 'warning',
timeout: 5000,
});
} else {
console.error("user '" + this.user?.username + "' logged out");
}
});
},
isAuthorizedAs(roles: string[]) {
return this.user !== null && roles.includes(this.user.role);
},
},
});