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
50 lines
1005 B
TypeScript
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,
|
|
}
|
|
})
|