diff --git a/src/components/FormLogin.vue b/src/components/FormLogin.vue index 1e5fbf4572adeea42c8d5cc5a7cfa9b2ab11d654..731e224e722324e37fb36ffd35f3bfe4ee2344f7 100644 --- a/src/components/FormLogin.vue +++ b/src/components/FormLogin.vue @@ -2,7 +2,6 @@ import { computed, ref, watch } from 'vue' import { useUserStore } from '@/stores/userStore' import ModalComponent from '@/components/ModalComponent.vue' -import { useRouter } from 'vue-router' import axios from 'axios' const username = ref<string>('') @@ -14,13 +13,11 @@ const resetEmail = ref<string>('') const emailRegex = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/ const userStore = useUserStore() -const router = useRouter() const isEmailValid = computed(() => emailRegex.test(resetEmail.value)) const submitForm = () => { userStore.login(username.value, password.value) - router.push('/hjem') } const toggleShowPassword = () => { diff --git a/src/components/FormRegister.vue b/src/components/FormRegister.vue index 8b3e34b6453ccaa8d170a91694d77dbed9b14604..384712994cf7ec631a7228240f8b6da3ac4db45b 100644 --- a/src/components/FormRegister.vue +++ b/src/components/FormRegister.vue @@ -2,7 +2,6 @@ import { computed, ref, watch } from 'vue' import { useUserStore } from '@/stores/userStore' import ToolTip from '@/components/ToolTip.vue' -import { useRouter } from 'vue-router' const firstname = ref<string>('') const lastname = ref<string>('') @@ -15,7 +14,6 @@ const showPassword = ref<boolean>(false) const errorMessage = ref<string>('') const userStore = useUserStore() -const router = useRouter() const nameRegex = /^[a-zA-Z ,.'-]+$/ const emailRegex = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/ @@ -37,7 +35,6 @@ const isFormInvalid = computed( const submitForm = () => { userStore.register(firstname.value, lastname.value, email.value, username.value, password.value) - router.push('/konfigurasjonSteg1') } const toggleShowPassword = () => { diff --git a/src/components/NavBarComponent.vue b/src/components/NavBarComponent.vue index 26cb0c8d8baf5bc333bd23af9405fac88d7afbbd..4306c66ceb664b9b6e87ba412027dce23d1d2fa0 100644 --- a/src/components/NavBarComponent.vue +++ b/src/components/NavBarComponent.vue @@ -43,18 +43,18 @@ </template> <script setup lang="ts"> -import { RouterLink, useRouter } from 'vue-router' +import { RouterLink } from 'vue-router' import { onMounted, ref } from 'vue' +import { useUserStore } from '@/stores/userStore' -const router = useRouter() +const userStore = useUserStore() const windowWidth = ref(window.innerWidth) const hamburgerOpen = ref(false) const isHamburger = ref(false) const logout = () => { - router.push('/login') - hamburgerOpen.value = false + userStore.logout() } const toggleMenu = () => { diff --git a/src/stores/userStore.ts b/src/stores/userStore.ts index 7d3b80eb1acea632670099dc8333161a71b47f71..fe31bd1a782e8feadd79d12e5fc3338ade7f9f93 100644 --- a/src/stores/userStore.ts +++ b/src/stores/userStore.ts @@ -38,7 +38,7 @@ export const useUserStore = defineStore('user', () => { user.value.lastname = lastname user.value.username = username - router.push('/') + router.push({ name: 'configurations1' }) }) .catch((error) => { const axiosError = error as AxiosError @@ -60,7 +60,7 @@ export const useUserStore = defineStore('user', () => { user.value.lastname = response.data.lastName user.value.username = response.data.username - router.push('/') + router.push({ name: 'home' }) }) .catch((error) => { const axiosError = error as AxiosError @@ -68,9 +68,18 @@ export const useUserStore = defineStore('user', () => { }) } + const logout = () => { + console.log('Logging out') + sessionStorage.removeItem('accessToken') + localStorage.removeItem('refreshToken') + user.value = defaultUser + router.push({ name: 'login' }) + } + return { - login, register, + login, + logout, errorMessage } })