Fix login bug. Improve reservations

This commit is contained in:
2024-05-21 16:32:31 -04:00
parent 737de91bbc
commit cd692a6f3b
10 changed files with 103 additions and 81 deletions

View File

@@ -1,5 +1,12 @@
import { boot } from 'quasar/wrappers';
import { Client, Account, Databases, Functions, ID } from 'appwrite';
import {
Client,
Account,
Databases,
Functions,
ID,
AppwriteException,
} from 'appwrite';
import { useAuthStore } from 'src/stores/auth';
import { Dialog, Notify } from 'quasar';
import type { Router } from 'vue-router';
@@ -90,7 +97,7 @@ async function logout() {
});
}
function login(email: string, password: string) {
async function login(email: string, password: string) {
const notification = Notify.create({
type: 'primary',
position: 'top',
@@ -100,31 +107,31 @@ function login(email: string, password: string) {
group: false,
});
const authStore = useAuthStore();
authStore
.login(email, password)
.then(() => {
notification({
type: 'positive',
message: 'Logged in!',
timeout: 2000,
spinner: false,
icon: 'check_circle',
});
console.log('Redirecting to index page');
appRouter.replace({ name: 'index' });
})
.catch(function (reason: Error) {
notification({
type: 'negative',
message: 'Login failed.',
timeout: 1,
});
try {
await authStore.login(email, password);
notification({
type: 'positive',
message: 'Logged in!',
timeout: 2000,
spinner: false,
icon: 'check_circle',
});
console.log('Redirecting to index page');
appRouter.replace({ name: 'index' });
} catch (error: unknown) {
notification({
type: 'negative',
message: 'Login failed.',
timeout: 2000,
});
if (error instanceof AppwriteException) {
Dialog.create({
title: 'Login Error!',
message: reason.message,
message: error.message,
persistent: true,
});
});
}
}
}
export {
client,