Refactor components. Improve design. Improve routing

This commit is contained in:
2023-11-17 17:15:37 -05:00
parent cbe4b5323e
commit f2d4ce12d4
17 changed files with 278 additions and 146 deletions

View File

@@ -1,11 +1,13 @@
import { boot } from 'quasar/wrappers';
import { Client, Account, Databases, ID } from 'appwrite';
import { useAuthStore } from 'src/stores/auth';
import { Dialog, Notify } from 'quasar';
import { Router } from 'vue-router';
const client = new Client();
client
.setEndpoint('https://cloud.appwrite.io/v1')
.setEndpoint('https://api.bab.toal.ca/v1')
.setProject('653ef6f76baf06d68034');
const account = new Account(client);
@@ -16,8 +18,64 @@ export default boot(({ app, urlPath, router }) => {
// Initialize store
const authStore = useAuthStore();
authStore.init().then(() => {
authStore.currentUser && router.push('/');
authStore.currentUser && router.replace('/');
});
});
export { client, account, databases, ID, appDatabaseId };
async function logout(router: Router) {
Dialog.create({
title: 'Logout',
message: 'Are you sure?',
cancel: true,
persistent: true,
}).onOk(async () => {
const authStore = useAuthStore();
await authStore.logout();
Notify.create({
message: 'Logged out!',
type: 'warning',
position: 'top',
timeout: 2000,
group: false,
});
router.replace({ name: 'login' });
});
}
function login(router: Router, email: string, password: string) {
const notification = Notify.create({
type: 'primary',
position: 'top',
spinner: true,
message: 'Logging you in...',
timeout: 8000,
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');
router.replace({ name: 'index' });
})
.catch(function (reason: Error) {
notification({
type: 'negative',
message: 'Login failed.',
timeout: 1,
});
Dialog.create({
title: 'Login Error!',
message: reason.message,
persistent: true,
});
});
}
export { client, account, databases, ID, appDatabaseId, login, logout };