Tweaking Login a bit more
This commit is contained in:
@@ -2,27 +2,35 @@ import { boot } from 'quasar/wrappers';
|
|||||||
import { Client, Account, Databases, ID } from 'appwrite';
|
import { Client, Account, Databases, ID } from 'appwrite';
|
||||||
import { useAuthStore } from 'src/stores/auth';
|
import { useAuthStore } from 'src/stores/auth';
|
||||||
import { Dialog, Notify } from 'quasar';
|
import { Dialog, Notify } from 'quasar';
|
||||||
import { Router } from 'vue-router';
|
import type { Router } from 'vue-router';
|
||||||
|
|
||||||
const client = new Client();
|
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
|
client
|
||||||
.setEndpoint('https://api.bab.toal.ca/v1')
|
.setEndpoint('https://apidev.bab.toal.ca/v1')
|
||||||
.setProject('653ef6f76baf06d68034');
|
.setProject('655a7116479b4d5a815f');
|
||||||
|
//TODO
|
||||||
|
const appDatabaseId = '';
|
||||||
|
|
||||||
const account = new Account(client);
|
const account = new Account(client);
|
||||||
const databases = new Databases(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
|
// Initialize store
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
authStore.init().then(() => {
|
await authStore.init();
|
||||||
authStore.currentUser ? router.replace('/') : router.replace('login');
|
appRouter = router;
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
async function logout(router: Router) {
|
async function logout() {
|
||||||
Dialog.create({
|
Dialog.create({
|
||||||
title: 'Logout',
|
title: 'Logout',
|
||||||
message: 'Are you sure?',
|
message: 'Are you sure?',
|
||||||
@@ -38,11 +46,11 @@ async function logout(router: Router) {
|
|||||||
timeout: 2000,
|
timeout: 2000,
|
||||||
group: false,
|
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({
|
const notification = Notify.create({
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
position: 'top',
|
position: 'top',
|
||||||
@@ -63,7 +71,7 @@ function login(router: Router, email: string, password: string) {
|
|||||||
icon: 'check_circle',
|
icon: 'check_circle',
|
||||||
});
|
});
|
||||||
console.log('Redirecting to index page');
|
console.log('Redirecting to index page');
|
||||||
router.replace({ name: 'index' });
|
appRouter.replace({ name: 'index' });
|
||||||
})
|
})
|
||||||
.catch(function (reason: Error) {
|
.catch(function (reason: Error) {
|
||||||
notification({
|
notification({
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
<q-item-section> {{ link.name }} </q-item-section>
|
<q-item-section> {{ link.name }} </q-item-section>
|
||||||
</q-item>
|
</q-item>
|
||||||
</template>
|
</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 avatar><q-icon name="logout" /></q-item-section
|
||||||
><q-item-section>Logout</q-item-section>
|
><q-item-section>Logout</q-item-section>
|
||||||
</q-item>
|
</q-item>
|
||||||
@@ -30,9 +30,6 @@
|
|||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { links } from 'src/router/navlinks.js';
|
import { links } from 'src/router/navlinks.js';
|
||||||
import { logout } from 'boot/appwrite';
|
import { logout } from 'boot/appwrite';
|
||||||
import { useRouter } from 'vue-router';
|
|
||||||
|
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
defineProps(['drawer']);
|
defineProps(['drawer']);
|
||||||
defineEmits(['drawer-toggle']);
|
defineEmits(['drawer-toggle']);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
></q-input>
|
></q-input>
|
||||||
<q-btn
|
<q-btn
|
||||||
type="submit"
|
type="submit"
|
||||||
@click="login($router, email, password)"
|
@click="login(email, password)"
|
||||||
label="Login"
|
label="Login"
|
||||||
color="primary"
|
color="primary"
|
||||||
></q-btn>
|
></q-btn>
|
||||||
|
|||||||
Reference in New Issue
Block a user