Skip to content

Commit

Permalink
fix fossasia#68 implemented better error handling for logout function (
Browse files Browse the repository at this point in the history
…fossasia#69)

* Add Home, Room Check-in

* fixed codacy

* clear netlify build

* Update SearchAttendee.vue

* Update ScanSearch

* Fixed navabr

* Update BaseTemplate.vue

* Removed bottom navbar and updated dropdown menu

* Minor fixes

* Added checklist to printModal and simplified router

* Name changes

* Fixed passwordModal and removed password requirement for stats

* Switched to template refs

* minor fixes

* Rearranged and renamed

* Fix codacy issues

* Changed casing

* Fix fossasia#31 Added dropdown list that allows user to choose which details to show on search

* Fixed format

* Fix codacy

* Minor fixes and renaming

* Minor fixes and moved some code to inline

* Fix fossasia#41 and codacy

* fix codacy

* Simplified code

* fix fossasia#48 created standard button component and replaced some buttons

* fix format

* Converted all buttons to standard component

* fixed format

* fix codacy

* Fix fossasia#40 standardised all p-6 except pages with scanners, optimised search function for mobile

* changed prop name

* removed activated classes

* Minor UI fixes

* fix fossasia#52 clicking print on search attendee now opens the print modal and logs name of card

* fix fossasia#51 new layout for print modal

* changed to margin

* removed grow flex

* minor fixes

* fix fossasia#50 created success notification that shows on print

* removed redundant code

* fix  margin of print modal

* changed naming

* switched to camel case, moved some functions to inline

* minor changes

* changed some refs to computed

* fix fossasia#49 fossasia#46 ported everything to stores

* fix codacy

* fix fossasia#59 fossasia#53 search and logout attached to respective APIs

* fix netlify

* fix netlify

* fix netlify

* fix codacy

* fix codacy

* fix codacy

* fix build

* fix codacy

* fix codacy

* fix fossasia#61 implemented API for checking in attendees in registration via scan or search

* fixed error

* added dayjs

* remove moment

* fix comments

* fix comments

* fix comment

* fix fossasia#68 implemented better error handling for logout function

* Update auth.js

* Update auth.js

---------

Co-authored-by: cweitat <[email protected]>
Co-authored-by: lizardon <[email protected]>
  • Loading branch information
3 people committed Aug 1, 2023
1 parent 46f2b92 commit 61b7299
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
21 changes: 15 additions & 6 deletions src/components/Modals/PasswordModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { EllipsisHorizontalIcon } from '@heroicons/vue/24/outline'
import StandardButton from '@/components/Shared/StandardButton.vue'
import { useAuthStore } from '@/stores/auth'
import { useLoadingStore } from '@/stores/loading'
import { useApiStore } from '@/stores/api'
import { useRouter } from 'vue-router'
const authStore = useAuthStore()
const loadingStore = useLoadingStore()
const apiStore = useApiStore()
const router = useRouter()
Expand All @@ -27,24 +29,31 @@ async function checkPassword() {
loadingStore.show = true
const payload = { password: passwordField.value }
await authStore.login(payload, 'auth/verify-password').then((res) => {
//verify password
if (res.result) {
authStore.logout('auth/logout').then((res) => console.log(res)) // post logout api and clear local storage
try {
const res = await authStore.verifyPassword(payload, 'auth/verify-password')
if (res === true) {
console.log('Password verified: correct')
await authStore.logout('auth/logout')
validPassword.value = true
emit('hidePasswordModal', false)
// sign out
router.push({
name: 'userAuth'
})
loadingStore.show = false
} else {
console.log('Password verified: incorrect')
loadingStore.show = false
disableButton.value = false
validPassword.value = false
passwordField.value = ''
}
})
} catch (error) {
console.log(error)
loadingStore.show = false
disableButton.value = false
validPassword.value = false
passwordField.value = ''
}
}
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/components/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const componentKey = ref(0)
:key="componentKey"
:show-password-modal="showPasswordModal"
@hide-password-modal="
() => {
($event) => {
showPasswordModal = $event
componentKey += 1
}
Expand Down
29 changes: 16 additions & 13 deletions src/stores/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@ import { defineStore } from 'pinia'
import { useApiStore } from '@/stores/api'

export const useAuthStore = defineStore('auth', () => {
// clear tokens
function logoutClear() {
localStorage.clear()
useApiStore().clearToken()
async function logout(route) {
try {
const res = await useApiStore().post(false, route)
localStorage.clear()
useApiStore().clearToken()
console.log('logout success')
return res.success
} catch (error) {
console.log('logout failed')
return await Promise.reject(error)
}
}

async function logout(route) {
async function verifyPassword(payload, route) {
try {
await useApiStore()
.post(false, route)
.then(() => {
logoutClear()
return true
})
const res = await useApiStore().post(true, route, payload, false)
return res.result
} catch (error) {
return false
return await Promise.reject(error)
}
}

return { logout }
return { logout, verifyPassword }
})

0 comments on commit 61b7299

Please sign in to comment.