INIT
This commit is contained in:
+41
@@ -0,0 +1,41 @@
|
||||
// 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.html';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is authenticated, redirect to login if not
|
||||
*/
|
||||
function checkAuth() {
|
||||
if (!pb.authStore.isValid) {
|
||||
window.location.href = 'index.html';
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current user
|
||||
*/
|
||||
function getCurrentUser() {
|
||||
return pb.authStore.model;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user