Initial working translator implementation
This commit is contained in:
commit
9439858b11
35 changed files with 5365 additions and 0 deletions
30
frontend/src/stores/auth.ts
Normal file
30
frontend/src/stores/auth.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
import { me as apiMe, logout as apiLogout } from '../api'
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
const user_id = ref<string | null>(null)
|
||||
const loaded = ref(false)
|
||||
|
||||
const isLoggedIn = computed(() => !!user_id.value && loaded.value)
|
||||
|
||||
async function check() {
|
||||
if (loaded.value) return
|
||||
try {
|
||||
const data = await apiMe()
|
||||
user_id.value = data.user_id
|
||||
} catch {
|
||||
user_id.value = null
|
||||
} finally {
|
||||
loaded.value = true
|
||||
}
|
||||
}
|
||||
|
||||
async function logout() {
|
||||
await apiLogout()
|
||||
user_id.value = null
|
||||
window.location.hash = '#/login'
|
||||
}
|
||||
|
||||
return { user_id, loaded, isLoggedIn, check, logout }
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue