My 13th reason (2.0)

This commit is contained in:
2024-09-20 16:34:17 +02:00
parent b9bb55cf49
commit be4c201d81
21 changed files with 129 additions and 131 deletions

View File

@ -30,21 +30,19 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { login, register } from '@/services/authentication'
import { useNotificationStore } from '@/stores/notifications'
import { useGameStore } from '@/stores/game'
import { useAssetStore } from '@/stores/assets'
import { useCookies } from '@vueuse/integrations/useCookies'
const gameStore = useGameStore()
const notifications = useNotificationStore()
const username = ref('')
const password = ref('')
// automatic login because of development
onMounted(async () => {
/**
* Fetch assets from the server
* Fetch sprite assets from the server
*/
await gameStore.fetchSpriteAssets()
const token = useCookies().get('token')
if (token) {
@ -56,7 +54,7 @@ onMounted(async () => {
async function loginFunc() {
// check if username and password are valid
if (username.value === '' || password.value === '') {
notifications.addNotification({ message: 'Please enter a valid username and password' })
gameStore.addNotification({ message: 'Please enter a valid username and password' })
return
}
@ -64,7 +62,7 @@ async function loginFunc() {
const response = await login(username.value, password.value)
if (response.success === undefined) {
notifications.addNotification({ message: response.error })
gameStore.addNotification({ message: response.error })
return
}
@ -76,7 +74,7 @@ async function loginFunc() {
async function registerFunc() {
// check if username and password are valid
if (username.value === '' || password.value === '') {
notifications.addNotification({ message: 'Please enter a valid username and password' })
gameStore.addNotification({ message: 'Please enter a valid username and password' })
return
}
@ -84,13 +82,13 @@ async function registerFunc() {
const response = await register(username.value, password.value)
if (response.success === undefined) {
notifications.addNotification({ message: response.error })
gameStore.addNotification({ message: response.error })
return
}
const loginSuccess = await loginFunc()
if (!loginSuccess) {
notifications.addNotification({ message: 'Login after registration failed. Please try logging in manually.' })
gameStore.addNotification({ message: 'Login after registration failed. Please try logging in manually.' })
}
}
</script>