Files
schedule-planner/frontend/src/stores/auth.js
Hera Zhao d3f3b4f37b
Some checks failed
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 3s
PR Preview / teardown-preview (pull_request) Has been skipped
Test / e2e-test (push) Failing after 55s
PR Preview / deploy-preview (pull_request) Failing after 40s
Refactor to Vue 3 + FastAPI + SQLite architecture
- Backend: FastAPI + SQLite (WAL mode), 22 tables, ~40 API endpoints
- Frontend: Vue 3 + Vite + Pinia + Vue Router, 8 views, 3 stores
- Database: migrate from JSON file to SQLite with proper schema
- Dockerfile: multi-stage build (node + python)
- Deploy: K8s manifests (namespace, deployment, service, ingress, pvc, backup)
- CI/CD: Gitea Actions (test, deploy, PR preview at pr-$id.planner.oci.euphon.net)
- Tests: 20 Cypress E2E test files, 196 test cases, ~85% coverage
- Doc: test-coverage.md with full feature coverage report

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 21:18:22 +00:00

43 lines
1.3 KiB
JavaScript

import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { api } from '../composables/useApi'
export const useAuthStore = defineStore('auth', () => {
const loggedIn = ref(false)
function checkLogin() {
const exp = localStorage.getItem('sp_login_expires')
loggedIn.value = exp && Date.now() < parseInt(exp)
return loggedIn.value
}
async function login(password) {
const buf = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(password))
const hash = Array.from(new Uint8Array(buf)).map(b => b.toString(16).padStart(2, '0')).join('')
await api.post('/api/login', { hash })
localStorage.setItem('sp_login_expires', String(Date.now() + 7 * 86400000))
loggedIn.value = true
}
function logout() {
localStorage.removeItem('sp_login_expires')
loggedIn.value = false
}
async function changePassword(oldPass, newPass) {
const hash = async (s) => {
const buf = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(s))
return Array.from(new Uint8Array(buf)).map(b => b.toString(16).padStart(2, '0')).join('')
}
await api.post('/api/change-password', {
oldHash: await hash(oldPass),
newHash: await hash(newPass),
})
}
// Auto-check on init
checkLogin()
return { loggedIn, checkLogin, login, logout, changePassword }
})