You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VerifyView.vue 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <template lang="pug">
  2. .wait-message
  3. p.verify-message Thanks for authenticating your email!
  4. p.verify-message Please give us a moment to redirect you back to the survey
  5. </template>
  6. <script>
  7. import { currentProfile, authenticator } from '../services'
  8. let hash = null
  9. let hashedAccessToken = null
  10. export default {
  11. name: 'VerifyView',
  12. async created() {
  13. hash = this.$route.params.hashedToken
  14. hashedAccessToken = this.grabCookie('siimee_access')
  15. try {
  16. this.isHashInUrl(hash)
  17. await this.doesAccessTokenExist(hashedAccessToken)
  18. await this.verifyActiveSession(hash)
  19. const sessionData = await this.isSessionTokenValid(hash)
  20. await currentProfile.login(
  21. sessionData.profileId,
  22. this.$waveui.notify,
  23. sessionData.accessToken,
  24. )
  25. } catch (err) {
  26. console.error(err)
  27. }
  28. this.$router.push('/')
  29. },
  30. methods: {
  31. grabCookie(cookieKey) {
  32. const cookies = document.cookie
  33. .split('; ')
  34. .reduce((prev, current) => {
  35. const [name, ...value] = current.split('=')
  36. prev[name] = value.join('=')
  37. return prev
  38. }, {})
  39. return `${cookieKey}` in cookies
  40. ? cookies[`${cookieKey}`]
  41. : undefined
  42. },
  43. isHashInUrl(hash) {
  44. if (!hash) throw new Error('URL contains no hash!')
  45. },
  46. async doesAccessTokenExist(hashedAccessToken) {
  47. if (!hashedAccessToken)
  48. throw new Error('accessToken not in cookie store!')
  49. },
  50. async verifyActiveSession(hashedToken) {
  51. const sessionData =
  52. await authenticator.verifyAuthSession(hashedToken)
  53. if (!sessionData.hashesMatch)
  54. throw new Error('Hash is not in activeSessions!')
  55. },
  56. async isSessionTokenValid(hash) {
  57. const sessionTokenIsValid =
  58. await authenticator.validateSession(hash)
  59. if (sessionTokenIsValid.error) {
  60. throw new Error(sessionTokenIsValid.error)
  61. } else return sessionTokenIsValid
  62. },
  63. },
  64. }
  65. </script>
  66. <style>
  67. .wait-message {
  68. margin: 5rem auto;
  69. text-align: center;
  70. width: 90%;
  71. max-width: 35rem;
  72. font-size: 150%;
  73. font-weight: bold;
  74. }
  75. </style>