Files
dreamweaver/admin-frontend/src/stores/user.ts
torin b8d3cb4644
Some checks are pending
Build and Push Docker Images / changes (push) Waiting to run
Build and Push Docker Images / build-backend (push) Blocked by required conditions
Build and Push Docker Images / build-frontend (push) Blocked by required conditions
Build and Push Docker Images / build-admin-frontend (push) Blocked by required conditions
wip: snapshot full local workspace state
2026-04-17 18:58:11 +08:00

50 lines
1005 B
TypeScript

import { defineStore } from 'pinia'
import { ref } from 'vue'
import { api } from '../api/client'
interface User {
id: string
name: string
avatar_url: string | null
provider: string
}
export const useUserStore = defineStore('user', () => {
const user = ref<User | null>(null)
const loading = ref(false)
async function fetchSession() {
loading.value = true
try {
const data = await api.get<{ user: User | null }>('/auth/session')
user.value = data.user
} catch {
user.value = null
} finally {
loading.value = false
}
}
function loginWithGithub() {
window.location.href = '/auth/github/signin'
}
function loginWithGoogle() {
window.location.href = '/auth/google/signin'
}
async function logout() {
await api.post('/auth/signout')
user.value = null
}
return {
user,
loading,
fetchSession,
loginWithGithub,
loginWithGoogle,
logout,
}
})