GF-6, #8 Added auth.
Some checks failed
Production PR / QA Tests (pull_request) Failing after 13s

This commit is contained in:
Liviu Burcusel 2026-01-07 09:54:06 +01:00
parent e8818d6eaa
commit 10e4363cbd
Signed by: liviu
GPG key ID: 6CDB37A4AD2C610C
60 changed files with 4855 additions and 160 deletions

45
app/stores/auth.ts Normal file
View file

@ -0,0 +1,45 @@
import { defineStore } from "pinia";
import { ref, computed } from "vue";
import { createAuthClient } from "better-auth/vue";
const authClient = createAuthClient();
export const useAuthStore = defineStore("useAuthStore", () => {
const session = ref<Awaited<ReturnType<typeof authClient.useSession>> | null>(null);
const lastError = ref<string | undefined>(undefined);
async function init() {
const data = await authClient.useSession(useFetch);
session.value = data;
lastError.value = undefined;
}
const user = computed(() => session.value?.data?.user);
const loading = computed(() => session.value?.isPending);
async function signIn(email: string, password: string) {
const { error } = await authClient.signIn.email({
email,
password,
callbackURL: "/",
});
if (error) {
lastError.value = error.message;
}
}
async function signOut() {
await authClient.signOut({});
navigateTo("/");
}
return {
init,
lastError,
loading,
signIn,
signOut,
user,
};
});