scaffold: Vue 3 frontend — router, stores, views, composables, layouts
Complete frontend skeleton: Vite + Vue 3 + TypeScript + Tailwind CSS, Pinia stores (auth, server, wipe, plugins), authenticated API composable, full route tree with auth guards, DashboardLayout with sidebar nav, 23 view stubs across auth/admin/public, all TypeScript interfaces. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
53
frontend/src/stores/auth.ts
Normal file
53
frontend/src/stores/auth.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
import type { User, License } from '@/types'
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
const user = ref<User | null>(null)
|
||||
const license = ref<License | null>(null)
|
||||
const accessToken = ref<string | null>(null)
|
||||
const refreshToken = ref<string | null>(null)
|
||||
|
||||
const isAuthenticated = computed(() => !!accessToken.value)
|
||||
const hasLicense = computed(() => !!license.value)
|
||||
const isLicenseActive = computed(() => license.value?.status === 'active')
|
||||
|
||||
function setAuth(data: { access_token: string; refresh_token: string; user: User }) {
|
||||
accessToken.value = data.access_token
|
||||
refreshToken.value = data.refresh_token
|
||||
user.value = data.user
|
||||
}
|
||||
|
||||
function setLicense(data: License) {
|
||||
license.value = data
|
||||
}
|
||||
|
||||
function logout() {
|
||||
user.value = null
|
||||
license.value = null
|
||||
accessToken.value = null
|
||||
refreshToken.value = null
|
||||
}
|
||||
|
||||
function hasModule(moduleSlug: string): boolean {
|
||||
return license.value?.modules_enabled?.includes(moduleSlug) ?? false
|
||||
}
|
||||
|
||||
return {
|
||||
user,
|
||||
license,
|
||||
accessToken,
|
||||
refreshToken,
|
||||
isAuthenticated,
|
||||
hasLicense,
|
||||
isLicenseActive,
|
||||
setAuth,
|
||||
setLicense,
|
||||
logout,
|
||||
hasModule,
|
||||
}
|
||||
}, {
|
||||
persist: {
|
||||
pick: ['accessToken', 'refreshToken', 'user', 'license'],
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user