Initial commit: Purrse personal finance app
Self-hosted, plugin-extensible personal finance manager built with ASP.NET Core 9.0, Vue 3 + Vuetify 3, and PostgreSQL 17. Backend (8 .NET projects): - Core: 19 domain models, 6 enums, 14 DTOs, 12 service interfaces - Data: EF Core DbContext, 16 entity configurations, category seeder - API: 14 controllers, 15 services, JWT auth, SignalR, middleware - Plugins: Abstractions + OFX/CSV/QIF file parsers - Tests: 28 xUnit tests (fingerprinting, duplicate detection, parsers) Frontend (Vue 3 + Vuetify 3 + TypeScript): - 13 views, Pinia stores, Axios API services with JWT interceptors - Dashboard, accounts, transactions, categories, imports, and more Deployment: - Docker Compose (PostgreSQL 17 + .NET API + nginx frontend) - Auto-migration on startup Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
import api from '@/services/api'
|
||||
import type { AuthResponse } from '@/types'
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
const token = ref<string | null>(null)
|
||||
const refreshTokenValue = ref<string | null>(null)
|
||||
const username = ref<string | null>(null)
|
||||
const expiresAt = ref<string | null>(null)
|
||||
|
||||
const isAuthenticated = computed(() => !!token.value)
|
||||
|
||||
function initialize() {
|
||||
token.value = localStorage.getItem('purrse_token')
|
||||
refreshTokenValue.value = localStorage.getItem('purrse_refresh_token')
|
||||
username.value = localStorage.getItem('purrse_username')
|
||||
expiresAt.value = localStorage.getItem('purrse_expires_at')
|
||||
}
|
||||
|
||||
function setAuth(auth: AuthResponse) {
|
||||
token.value = auth.token
|
||||
refreshTokenValue.value = auth.refreshToken
|
||||
username.value = auth.username
|
||||
expiresAt.value = auth.expiresAt
|
||||
localStorage.setItem('purrse_token', auth.token)
|
||||
localStorage.setItem('purrse_refresh_token', auth.refreshToken)
|
||||
localStorage.setItem('purrse_username', auth.username)
|
||||
localStorage.setItem('purrse_expires_at', auth.expiresAt)
|
||||
}
|
||||
|
||||
async function login(usernameInput: string, password: string) {
|
||||
const { data } = await api.post<AuthResponse>('/auth/login', { username: usernameInput, password })
|
||||
setAuth(data)
|
||||
}
|
||||
|
||||
async function register(usernameInput: string, email: string, password: string) {
|
||||
const { data } = await api.post<AuthResponse>('/auth/register', { username: usernameInput, email, password })
|
||||
setAuth(data)
|
||||
}
|
||||
|
||||
async function refreshToken() {
|
||||
if (!refreshTokenValue.value) throw new Error('No refresh token')
|
||||
const { data } = await api.post<AuthResponse>('/auth/refresh', { refreshToken: refreshTokenValue.value })
|
||||
setAuth(data)
|
||||
}
|
||||
|
||||
function logout() {
|
||||
token.value = null
|
||||
refreshTokenValue.value = null
|
||||
username.value = null
|
||||
expiresAt.value = null
|
||||
localStorage.removeItem('purrse_token')
|
||||
localStorage.removeItem('purrse_refresh_token')
|
||||
localStorage.removeItem('purrse_username')
|
||||
localStorage.removeItem('purrse_expires_at')
|
||||
}
|
||||
|
||||
return { token, username, expiresAt, isAuthenticated, initialize, login, register, refreshToken, logout }
|
||||
})
|
||||
Reference in New Issue
Block a user