feat: initial Vue web app with OTP login

This commit is contained in:
2026-05-18 16:02:43 +03:30
commit 26e59e03e0
19 changed files with 2256 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
import { defineStore } from 'pinia';
import { ref, computed } from 'vue';
import type { User } from '@/api/auth';
import { fetchMe } from '@/api/auth';
const TOKEN_KEY = 'montime_access_token';
export const useAuthStore = defineStore('auth', () => {
const token = ref<string | null>(localStorage.getItem(TOKEN_KEY));
const user = ref<User | null>(null);
const isLoggedIn = computed(() => Boolean(token.value));
function setSession(accessToken: string, profile: User) {
token.value = accessToken;
user.value = profile;
localStorage.setItem(TOKEN_KEY, accessToken);
}
function logout() {
token.value = null;
user.value = null;
localStorage.removeItem(TOKEN_KEY);
}
async function loadUser() {
if (!token.value) {
return;
}
try {
user.value = await fetchMe(token.value);
} catch {
logout();
}
}
return {
token,
user,
isLoggedIn,
setSession,
logout,
loadUser,
};
});