Add missing file

This commit is contained in:
2023-11-13 21:38:22 -05:00
parent 5ec697b94a
commit ace92fd2de

31
src/stores/auth.ts Normal file
View File

@@ -0,0 +1,31 @@
import { defineStore } from 'pinia';
import { ID, account, client } from 'boot/appwrite';
import type { Models } from 'appwrite';
import { ref } from 'vue';
export const useAuthStore = defineStore('auth', () => {
const currentUser = ref<Models.User<Models.Preferences> | null>(null);
async function init() {
try {
currentUser.value = await account.get();
} catch {
return (currentUser.value = null);
}
}
async function register(email: string, password: string) {
await account.create(ID.unique(), email, password);
return await login(email, password);
}
async function login(email: string, password: string) {
await account.createEmailSession(email, password);
currentUser.value = await account.get();
}
function logout() {
return account.deleteSession('current').then((currentUser.value = null));
}
return { currentUser, register, login, logout, init };
});