Files
2025-12-15 14:54:29 -06:00

42 lines
819 B
JavaScript

// Authentication functions
/**
* Login with email and password
*/
async function login(email, password) {
try {
const authData = await pb.collection('users').authWithPassword(email, password);
return authData;
} catch (error) {
console.error('Login error:', error);
throw new Error(error.message || 'Login failed. Please check your credentials.');
}
}
/**
* Logout current user
*/
function logout() {
pb.authStore.clear();
window.location.href = 'index';
}
/**
* Check if user is authenticated, redirect to login if not
*/
function checkAuth() {
if (!pb.authStore.isValid) {
window.location.href = 'index';
return false;
}
return true;
}
/**
* Get current user
*/
function getCurrentUser() {
return pb.authStore.model;
}