My 13th reason (2.0)
This commit is contained in:
@ -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>
|
||||
|
Reference in New Issue
Block a user