Compare commits

...

2 Commits

Author SHA1 Message Date
Ferdinand Thiessen 8e552ba508 feat(app): Set lifetime to 14 days on capacitor.
Do not annoy users on capacitory apps with daily logging in again
2021-12-05 13:45:50 +01:00
Ferdinand Thiessen 49c3ec74ba fix(api): Load current user in login function of mainStore 2021-12-05 13:45:50 +01:00
2 changed files with 13 additions and 5 deletions

View File

@ -67,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 }) {

View File

@ -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({