[FEAT] Auth. and user projects

This commit is contained in:
2026-01-01 18:23:42 +01:00
parent 8e1b5fa77c
commit 7e51896d00
11 changed files with 590 additions and 16 deletions

View File

@@ -0,0 +1,39 @@
import { defineStore } from 'pinia';
import PocketBase from 'pocketbase';
import { ref } from 'vue';
export const useAuthStore = defineStore('auth', () => {
const pb = new PocketBase(import.meta.env.VITE_POCKETBASE_URL);
const user = ref(pb.authStore.model);
// Sync user state on change
pb.authStore.onChange(() => {
user.value = pb.authStore.model;
});
async function login(email: string, password: string) {
await pb.collection('users').authWithPassword(email, password);
}
async function register(email: string, password: string, passwordConfirm: string) {
await pb.collection('users').create({
email,
password,
passwordConfirm,
});
// Auto login after register
await login(email, password);
}
function logout() {
pb.authStore.clear();
}
return {
pb,
user,
login,
register,
logout,
};
});