From 85d64f23eb802d9e700b9b91e566e301df9da251 Mon Sep 17 00:00:00 2001 From: Dennis Postma Date: Thu, 14 Nov 2024 22:20:46 +0100 Subject: [PATCH] #238: Remove hash from URL with JS instead of full redirect --- src/components/login/NewPasswordForm.vue | 11 +++++------ src/components/screens/Login.vue | 11 ++++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/components/login/NewPasswordForm.vue b/src/components/login/NewPasswordForm.vue index 7798ca7..3d7c62c 100644 --- a/src/components/login/NewPasswordForm.vue +++ b/src/components/login/NewPasswordForm.vue @@ -60,18 +60,17 @@ async function newPasswordFunc() { return } - /** - * @TODO: #238, this wont work if we redirect to the login page - * Find a way to just "close" this screen instead of redirecting - */ gameStore.addNotification({ title: 'Success', message: 'Password changed successfully' }) - window.location.href = '/' + + window.history.replaceState(null, '', window.location.pathname) + emit('switchToLogin') } function cancelNewPassword() { - window.location.href = '/' + window.history.replaceState(null, '', windowlocation.pathname) + emit('switchToLogin') } diff --git a/src/components/screens/Login.vue b/src/components/screens/Login.vue index a5c71bc..7180776 100644 --- a/src/components/screens/Login.vue +++ b/src/components/screens/Login.vue @@ -15,10 +15,10 @@ - + - + @@ -35,11 +35,16 @@ import NewPasswordForm from '@/components/login/NewPasswordForm.vue' import ResetPassword from '@/components/login/ResetPasswordModal.vue' const isPasswordResetFormShown = ref(false) -const doesUrlHaveToken = window.location.hash.includes('#') +const doesUrlHaveToken = ref(window.location.hash !== '') const gameStore = useGameStore() const currentForm = ref('login') +function switchToLogin() { + currentForm.value = 'login' + doesUrlHaveToken.value = false +} + // automatic login because of development onMounted(async () => { const token = useCookies().get('token')