Files
osdb-1-claude-opusplan/frontend/src/stores/authStore.ts
T
juliaandClaude Sonnet 4.6 1b381d9385 feat: protect write endpoints with JWT auth (story #08)
Add bcrypt user file auth, JWT middleware on all write routes, Pinia
authStore with localStorage persistence, login view with redirect
support, and v-if guards on all CRUD controls and admin nav link.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-19 11:18:42 +02:00

24 lines
669 B
TypeScript

import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { login as apiLogin } from '../api/auth'
const TOKEN_KEY = 'auth_token'
export const useAuthStore = defineStore('auth', () => {
const token = ref<string | null>(localStorage.getItem(TOKEN_KEY))
const isLoggedIn = computed(() => token.value !== null)
async function login(username: string, password: string) {
const resp = await apiLogin(username, password)
token.value = resp.token
localStorage.setItem(TOKEN_KEY, resp.token)
}
function logout() {
token.value = null
localStorage.removeItem(TOKEN_KEY)
}
return { token, isLoggedIn, login, logout }
})