Add notifications to basic auth. Basic Auth DONE
This commit is contained in:
@@ -98,7 +98,7 @@ module.exports = configure(function (/* ctx */) {
|
|||||||
// directives: [],
|
// directives: [],
|
||||||
|
|
||||||
// Quasar plugins
|
// Quasar plugins
|
||||||
plugins: ['LocalStorage', 'SessionStorage'],
|
plugins: ['Notify', 'LocalStorage', 'SessionStorage'],
|
||||||
},
|
},
|
||||||
|
|
||||||
// animations: 'all', // --- includes all animations
|
// animations: 'all', // --- includes all animations
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import { account } from 'boot/appwrite';
|
|||||||
import type { Models } from 'appwrite';
|
import type { Models } from 'appwrite';
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
import { useQuasar } from 'quasar';
|
||||||
|
|
||||||
const linksList = [
|
const linksList = [
|
||||||
{
|
{
|
||||||
@@ -51,6 +52,7 @@ const linksList = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const q = useQuasar();
|
||||||
const leftDrawerOpen = ref(false);
|
const leftDrawerOpen = ref(false);
|
||||||
|
|
||||||
const loggedInUser = ref<Models.User<Models.Preferences> | null>();
|
const loggedInUser = ref<Models.User<Models.Preferences> | null>();
|
||||||
@@ -63,6 +65,13 @@ account.get().then((result) => {
|
|||||||
|
|
||||||
async function logout() {
|
async function logout() {
|
||||||
await account.deleteSession('current');
|
await account.deleteSession('current');
|
||||||
|
q.notify({
|
||||||
|
message: 'Logged out!',
|
||||||
|
type: 'warning',
|
||||||
|
position: 'top',
|
||||||
|
timeout: 2000,
|
||||||
|
group: false,
|
||||||
|
});
|
||||||
router.push({ name: 'login' });
|
router.push({ name: 'login' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,13 +12,6 @@
|
|||||||
<div class="text-center q-pt-sm">
|
<div class="text-center q-pt-sm">
|
||||||
<div class="col text-h6">Log in</div>
|
<div class="col text-h6">Log in</div>
|
||||||
</div>
|
</div>
|
||||||
<q-card-section v-if="errorMessage">
|
|
||||||
<div class="alert-box">
|
|
||||||
<strong>Error!</strong>
|
|
||||||
<br />
|
|
||||||
{{ errorMessage }}
|
|
||||||
</div>
|
|
||||||
</q-card-section>
|
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<q-form class="q-gutter-md">
|
<q-form class="q-gutter-md">
|
||||||
@@ -72,25 +65,12 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.alert-box {
|
|
||||||
color: #666;
|
|
||||||
border: 1px solid red;
|
|
||||||
border-radius: 4px;
|
|
||||||
padding: 20px;
|
|
||||||
background-color: #f8f8f8;
|
|
||||||
}
|
|
||||||
|
|
||||||
strong {
|
|
||||||
color: red;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { AppwriteException } from 'appwrite';
|
import { AppwriteException } from 'appwrite';
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { account } from 'boot/appwrite';
|
import { account } from 'boot/appwrite';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
import { useQuasar } from 'quasar';
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'LoginPage',
|
name: 'LoginPage',
|
||||||
@@ -100,15 +80,35 @@ const email = ref('');
|
|||||||
const password = ref('');
|
const password = ref('');
|
||||||
const errorMessage = ref('');
|
const errorMessage = ref('');
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const q = useQuasar();
|
||||||
|
|
||||||
function login(email: string, password: string) {
|
function login(email: string, password: string) {
|
||||||
|
const notification = q.notify({
|
||||||
|
type: 'primary',
|
||||||
|
position: 'top',
|
||||||
|
spinner: true,
|
||||||
|
message: 'Logging you in...',
|
||||||
|
timeout: 2000,
|
||||||
|
group: false,
|
||||||
|
});
|
||||||
account
|
account
|
||||||
.createEmailSession(email, password)
|
.createEmailSession(email, password)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
notification({
|
||||||
|
type: 'positive',
|
||||||
|
message: 'Logged in!',
|
||||||
|
timeout: 2000,
|
||||||
|
spinner: false,
|
||||||
|
icon: 'check_circle',
|
||||||
|
});
|
||||||
router.push({ name: 'index' });
|
router.push({ name: 'index' });
|
||||||
})
|
})
|
||||||
.catch((reason: AppwriteException) => {
|
.catch((reason: AppwriteException) => {
|
||||||
errorMessage.value = reason.message;
|
notification({
|
||||||
|
type: 'negative',
|
||||||
|
message: 'Login failed. Error:' + reason.message,
|
||||||
|
timeout: 2000,
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user