diff --git a/src/screens/Login.vue b/src/screens/Login.vue
index e1113c8..99c59b2 100644
--- a/src/screens/Login.vue
+++ b/src/screens/Login.vue
@@ -8,12 +8,14 @@

-
-
Don't have an account?
+
Don't have an account?
+
+
+
+
+
@@ -44,9 +69,7 @@ import { useCookies } from '@vueuse/integrations/useCookies'
const gameStore = useGameStore()
const username = ref('')
const password = ref('')
-let formError = false
-let notification = ''
-
+const switchForm = ref('login')
// automatic login because of development
onMounted(async () => {
const token = useCookies().get('token')
@@ -59,8 +82,7 @@ onMounted(async () => {
async function loginFunc() {
// check if username and password are valid
if (username.value === '' || password.value === '') {
- notification = 'Please enter a valid username and password'
- formError = true
+ gameStore.setLoginMessage('Please enter a valid username and password')
return
}
@@ -68,12 +90,9 @@ async function loginFunc() {
const response = await login(username.value, password.value)
if (response.success === undefined) {
- notification = response.error
- formError = true
+ gameStore.setLoginMessage(response.error)
return
}
-
- console.log(formError)
gameStore.setToken(response.token)
gameStore.initConnection()
return true // Indicate success
@@ -82,8 +101,7 @@ async function loginFunc() {
async function registerFunc() {
// check if username and password are valid
if (username.value === '' || password.value === '') {
- notification = 'Please enter a valid username and password'
- formError = true
+ gameStore.setLoginMessage('Please enter a valid username and password')
return
}
@@ -91,15 +109,13 @@ async function registerFunc() {
const response = await register(username.value, password.value)
if (response.success === undefined) {
- notification = response.error
- formError = true
+ gameStore.setLoginMessage(response.error)
return
}
const loginSuccess = await loginFunc()
if (!loginSuccess) {
- notification = 'Login after registration failed. Please try logging in manually.'
- formError = true
+ gameStore.setLoginMessage('Login after registration failed. Please try logging in manually.')
}
}
diff --git a/src/stores/gameStore.ts b/src/stores/gameStore.ts
index db53fa5..ab8ff03 100644
--- a/src/stores/gameStore.ts
+++ b/src/stores/gameStore.ts
@@ -7,6 +7,7 @@ import { useCookies } from '@vueuse/integrations/useCookies'
export const useGameStore = defineStore('game', {
state: () => {
return {
+ loginMessage: null as string | null,
notifications: [] as Notification[],
assets: [] as Asset[],
token: '' as string | null,
@@ -31,6 +32,9 @@ export const useGameStore = defineStore('game', {
}
},
actions: {
+ setLoginMessage(message: string | null) {
+ this.loginMessage = message
+ },
addNotification(notification: Notification) {
if (!notification.id) {
notification.id = Math.random().toString(16)