Tweaking Login a bit more

This commit is contained in:
2023-11-19 21:35:31 -05:00
parent 7b70c13f3f
commit 326a556826
3 changed files with 22 additions and 17 deletions

View File

@@ -2,27 +2,35 @@ 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';
import type { Router } from 'vue-router';
const client = new Client();
// appwrite.io SaaS
// client
// .setEndpoint('https://api.bab.toal.ca/v1')
// .setProject('653ef6f76baf06d68034');
// const appDatabaseId = '654ac5044d1c446feb71';
// Private self-hosted appwrite
client
.setEndpoint('https://api.bab.toal.ca/v1')
.setProject('653ef6f76baf06d68034');
.setEndpoint('https://apidev.bab.toal.ca/v1')
.setProject('655a7116479b4d5a815f');
//TODO
const appDatabaseId = '';
const account = new Account(client);
const databases = new Databases(client);
const appDatabaseId = '654ac5044d1c446feb71';
let appRouter: Router;
export default boot(({ app, urlPath, router }) => {
export default boot(async ({ app, router }) => {
// Initialize store
const authStore = useAuthStore();
authStore.init().then(() => {
authStore.currentUser ? router.replace('/') : router.replace('login');
});
await authStore.init();
appRouter = router;
});
async function logout(router: Router) {
async function logout() {
Dialog.create({
title: 'Logout',
message: 'Are you sure?',
@@ -38,11 +46,11 @@ async function logout(router: Router) {
timeout: 2000,
group: false,
});
router.replace({ name: 'login' });
appRouter.replace({ name: 'login' });
});
}
function login(router: Router, email: string, password: string) {
function login(email: string, password: string) {
const notification = Notify.create({
type: 'primary',
position: 'top',
@@ -63,7 +71,7 @@ function login(router: Router, email: string, password: string) {
icon: 'check_circle',
});
console.log('Redirecting to index page');
router.replace({ name: 'index' });
appRouter.replace({ name: 'index' });
})
.catch(function (reason: Error) {
notification({

View File

@@ -17,7 +17,7 @@
<q-item-section> {{ link.name }} </q-item-section>
</q-item>
</template>
<q-item clickable v-ripple @click="logout(router)">
<q-item clickable v-ripple @click="logout()">
<q-item-section avatar><q-icon name="logout" /></q-item-section
><q-item-section>Logout</q-item-section>
</q-item>
@@ -30,9 +30,6 @@
import { defineComponent } from 'vue';
import { links } from 'src/router/navlinks.js';
import { logout } from 'boot/appwrite';
import { useRouter } from 'vue-router';
const router = useRouter();
defineProps(['drawer']);
defineEmits(['drawer-toggle']);

View File

@@ -31,7 +31,7 @@
></q-input>
<q-btn
type="submit"
@click="login($router, email, password)"
@click="login(email, password)"
label="Login"
color="primary"
></q-btn>