23 lines
No EOL
615 B
TypeScript
23 lines
No EOL
615 B
TypeScript
import { defineStore } from "pinia"
|
|
import { computed, ref } from "vue"
|
|
import { trpcClient } from "./trpc"
|
|
|
|
export const useAuth = defineStore("auth", () => {
|
|
const authenticatedUser = ref<{ id: string; name: string } | null>(null)
|
|
const requiredUser = computed(() => authenticatedUser.value!)
|
|
|
|
return {
|
|
authenticatedUser,
|
|
requiredUser,
|
|
async fetchSelf() {
|
|
authenticatedUser.value = (await trpcClient.getSelf.query()).user
|
|
},
|
|
async login(username: string) {
|
|
const { id } = await trpcClient.login.mutate({ name: username })
|
|
authenticatedUser.value = {
|
|
id,
|
|
name: username
|
|
}
|
|
}
|
|
}
|
|
}) |