feat(app): Set lifetime to 14 days on capacitor.
Do not annoy users on capacitory apps with daily logging in again
This commit is contained in:
parent
49c3ec74ba
commit
8e552ba508
|
@ -70,10 +70,11 @@
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import { Loading, Notify } from 'quasar';
|
import { Loading, Notify, useQuasar } from 'quasar';
|
||||||
import { api, notEmpty, PersistentStorage, useMainStore, useUserStore } from '@flaschengeist/api';
|
import { api, notEmpty, PersistentStorage, useMainStore } from '@flaschengeist/api';
|
||||||
import { PasswordInput } from '@flaschengeist/api/components';
|
import { PasswordInput } from '@flaschengeist/api/components';
|
||||||
import { defineComponent, onMounted, ref } from 'vue';
|
import { defineComponent, onMounted, ref } from 'vue';
|
||||||
|
import { useSessionStore } from 'app/api';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'PageLogin',
|
name: 'PageLogin',
|
||||||
|
@ -88,8 +89,9 @@ export default defineComponent({
|
||||||
const mainRoute = { name: 'dashboard' };
|
const mainRoute = { name: 'dashboard' };
|
||||||
|
|
||||||
const mainStore = useMainStore();
|
const mainStore = useMainStore();
|
||||||
const userStore = useUserStore();
|
const sessionStore = useSessionStore();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const quasar = useQuasar();
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (mainStore.session) void router.replace(mainRoute);
|
if (mainStore.session) void router.replace(mainRoute);
|
||||||
|
@ -115,10 +117,14 @@ export default defineComponent({
|
||||||
const status = await mainStore.login(userid.value, password.value);
|
const status = await mainStore.login(userid.value, password.value);
|
||||||
|
|
||||||
if (status === true) {
|
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'];
|
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 {
|
} else {
|
||||||
|
// Login failed, notify and reset form
|
||||||
password.value = '';
|
password.value = '';
|
||||||
if (status === 401) {
|
if (status === 401) {
|
||||||
Notify.create({
|
Notify.create({
|
||||||
|
|
Loading…
Reference in New Issue