From 0b8a1794a0dc3efb280799a5c35386196ffe8727 Mon Sep 17 00:00:00 2001 From: Janis Date: Wed, 10 Dec 2025 11:32:29 +0100 Subject: [PATCH] feat: FRO-2 Implement Login Component --- src/main.ts | 3 +++ src/router/index.ts | 1 + src/types/GameTypes.ts | 2 ++ src/views/LoginView.vue | 5 ++++- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 7832288..13dd503 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,6 +11,7 @@ import 'quasar/dist/quasar.css' import { createPinia } from 'pinia' import axios from 'axios' import VueAxios from 'vue-axios' +import {useUserInfo} from "@/composables/useUserInfo.ts"; const app = createApp(App) const pinia = createPinia() @@ -33,6 +34,8 @@ axios.interceptors.response.use( res => res, err => { if (err.response?.status === 401) { + const info = useUserInfo(); + info.clearUserInfo(); router.replace({name: 'login'}); } return Promise.reject(err); diff --git a/src/router/index.ts b/src/router/index.ts index 5b38bdb..0c2ed87 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -49,6 +49,7 @@ router.beforeEach(async (to, from, next) => { ); next(); } catch (err) { + info.clearUserInfo(); next('/login'); } }); diff --git a/src/types/GameTypes.ts b/src/types/GameTypes.ts index 782461b..9c3bca5 100644 --- a/src/types/GameTypes.ts +++ b/src/types/GameTypes.ts @@ -45,3 +45,5 @@ type WonInfo = { winner: PodiumPlayer | null allPlayers: PodiumPlayer[] } + +export type { GameInfo, LobbyInfo, TieInfo, TrumpInfo, WonInfo } diff --git a/src/views/LoginView.vue b/src/views/LoginView.vue index 762ab63..50997d6 100644 --- a/src/views/LoginView.vue +++ b/src/views/LoginView.vue @@ -62,6 +62,7 @@ import { useQuasar } from 'quasar' import { ref } from 'vue' import axios from "axios"; import router from "@/router"; +import {useUserInfo} from "@/composables/useUserInfo.ts"; const api = window?.__RUNTIME_CONFIG__?.API_URL; @@ -71,12 +72,14 @@ const username = ref(null) const password = ref(null) const inProgress = ref(false) const loginError = ref('') +const uInfo = useUserInfo() const onSubmit = () => { if (inProgress.value) return inProgress.value = true loginError.value = '' - axios.post(`${api}/login`, {username: username.value, password: password.value}, {withCredentials: true}).then(response => { + axios.post(`${api}/login`, {username: username.value, password: password.value}, {withCredentials: true}).then((response) => { + uInfo.setUserInfo(response.data.user.username, response.data.user.id) router.push("/") }).catch(() => { loginError.value = 'Invalid username or password'