Compare commits

..

No commits in common. "b2e69e3b6192208fa752131d5ed9dc4a00ff1085" and "656d7a9e3c0c85b7f7cf90188bf944425d39d7b1" have entirely different histories.

3 changed files with 5 additions and 21 deletions

View File

@ -38,10 +38,6 @@ 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 || [];
},
@ -67,10 +63,8 @@ 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

@ -20,10 +20,6 @@ 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);
},

View File

@ -70,11 +70,10 @@
<script lang="ts">
import { useRouter } from 'vue-router';
import { Loading, Notify, useQuasar } from 'quasar';
import { api, notEmpty, PersistentStorage, useMainStore } from '@flaschengeist/api';
import { Loading, Notify } from 'quasar';
import { api, notEmpty, PersistentStorage, useMainStore, useUserStore } 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',
@ -89,9 +88,8 @@ export default defineComponent({
const mainRoute = { name: 'dashboard' };
const mainStore = useMainStore();
const sessionStore = useSessionStore();
const userStore = useUserStore();
const router = useRouter();
const quasar = useQuasar();
onMounted(() => {
if (mainStore.session) void router.replace(mainRoute);
@ -117,14 +115,10 @@ export default defineComponent({
const status = await mainStore.login(userid.value, password.value);
if (status === 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.
mainStore.user = await userStore.getUser(userid.value, true);
const x = router.currentRoute.value.query['redirect'];
void router.push(!!x && typeof x === 'string' ? { path: x } : mainRoute);
void router.push(typeof x === 'string' ? { path: x } : mainRoute);
} else {
// Login failed, notify and reset form
password.value = '';
if (status === 401) {
Notify.create({