Compare commits
4 Commits
656d7a9e3c
...
b2e69e3b61
Author | SHA1 | Date |
---|---|---|
Ferdinand Thiessen | b2e69e3b61 | |
Ferdinand Thiessen | 6652025143 | |
Ferdinand Thiessen | e3856c77d4 | |
Ferdinand Thiessen | 83f32ea82a |
|
@ -38,6 +38,10 @@ export const useMainStore = defineStore({
|
|||
if (this.user === undefined) throw 'Not logged in, this should not be called';
|
||||
return this.user;
|
||||
},
|
||||
currentSession(): FG.Session {
|
||||
if (this.session === undefined) throw 'Not logged in, this should not be called';
|
||||
return this.session;
|
||||
},
|
||||
permissions(): string[] {
|
||||
return this.user?.permissions || [];
|
||||
},
|
||||
|
@ -63,8 +67,10 @@ export const useMainStore = defineStore({
|
|||
},
|
||||
|
||||
async login(userid: string, password: string) {
|
||||
const userStore = useUserStore();
|
||||
try {
|
||||
const { data } = await api.post<FG.Session>('/auth', { userid, password });
|
||||
this.user = await userStore.getUser(data.userid, true);
|
||||
this.session = fixSession(data);
|
||||
return true;
|
||||
} catch ({ response }) {
|
||||
|
|
|
@ -20,6 +20,10 @@ export const useUserStore = defineStore({
|
|||
getters: {},
|
||||
|
||||
actions: {
|
||||
/**
|
||||
* @deprecated Use getUser instead, will be removed with first beta release
|
||||
* @todo Remove with first beta release
|
||||
*/
|
||||
findUser(userid: string) {
|
||||
return this.users.find((user) => user.userid === userid);
|
||||
},
|
||||
|
|
|
@ -70,10 +70,11 @@
|
|||
|
||||
<script lang="ts">
|
||||
import { useRouter } from 'vue-router';
|
||||
import { Loading, Notify } from 'quasar';
|
||||
import { api, notEmpty, PersistentStorage, useMainStore, useUserStore } from '@flaschengeist/api';
|
||||
import { Loading, Notify, useQuasar } from 'quasar';
|
||||
import { api, notEmpty, PersistentStorage, useMainStore } from '@flaschengeist/api';
|
||||
import { PasswordInput } from '@flaschengeist/api/components';
|
||||
import { defineComponent, onMounted, ref } from 'vue';
|
||||
import { useSessionStore } from 'app/api';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'PageLogin',
|
||||
|
@ -88,8 +89,9 @@ export default defineComponent({
|
|||
const mainRoute = { name: 'dashboard' };
|
||||
|
||||
const mainStore = useMainStore();
|
||||
const userStore = useUserStore();
|
||||
const sessionStore = useSessionStore();
|
||||
const router = useRouter();
|
||||
const quasar = useQuasar();
|
||||
|
||||
onMounted(() => {
|
||||
if (mainStore.session) void router.replace(mainRoute);
|
||||
|
@ -115,10 +117,14 @@ export default defineComponent({
|
|||
const status = await mainStore.login(userid.value, password.value);
|
||||
|
||||
if (status === true) {
|
||||
mainStore.user = await userStore.getUser(userid.value, true);
|
||||
// On capacitor we set the lifetime to at least two weeks to not annoy users.
|
||||
if (quasar.platform.is.capacitor)
|
||||
void sessionStore.updateSession(14 * 24 * 60 * 60, mainStore.currentSession.token);
|
||||
// Redirect user to previous page, if any.
|
||||
const x = router.currentRoute.value.query['redirect'];
|
||||
void router.push(typeof x === 'string' ? { path: x } : mainRoute);
|
||||
void router.push(!!x && typeof x === 'string' ? { path: x } : mainRoute);
|
||||
} else {
|
||||
// Login failed, notify and reset form
|
||||
password.value = '';
|
||||
if (status === 401) {
|
||||
Notify.create({
|
||||
|
|
Loading…
Reference in New Issue