add new lights, add login and role to it, add services page

This commit is contained in:
Adrian Zuercher
2025-08-09 18:00:36 +02:00
parent 7d2ab814da
commit 1697a4dcfd
56 changed files with 1337 additions and 290 deletions

31
src/vueLib/login/login.ts Normal file
View File

@@ -0,0 +1,31 @@
import { appApi } from 'src/boot/axios';
import { useUserStore } from './userStore';
const useStore = useUserStore();
export function useLogin() {
async function login(user: string, password: string) {
await appApi
.post('/login', { user: user, password: password })
.then((resp) => {
useStore.setToken(resp.data.token);
})
.catch((err) => {
throw err;
});
}
function logout() {
useStore.logout();
}
function isTokenValid() {
const token = localStorage.getItem('token');
if (token === null) return false;
const payload = JSON.parse(atob(token.split('.')[1] ?? ''));
const currentTime = Math.floor(Date.now() / 1000);
return payload.exp > currentTime;
}
return { login, logout, isTokenValid };
}