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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 { Authenticator } from '../services/auth.service.js'
  8. export default {
  9. name: 'VerifyView',
  10. data: () => ({
  11. authenticator: {},
  12. answers: {},
  13. hash: undefined,
  14. sessionToken: undefined,
  15. }),
  16. async created() {
  17. this.authenticator = new Authenticator()
  18. this.hash = this.$route.params.email
  19. this.sessionToken = this.grabCookie('siimee_session')
  20. try {
  21. this.isHashInUrl(this.hash)
  22. this.doesEmailMatch(this.hash)
  23. this.doesSessionTokenExist(this.sessionToken)
  24. this.isSessionTokenValid(this.sessionToken)
  25. } catch (err) {
  26. console.error(err)
  27. }
  28. this.$router.push('/onboarding')
  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. async getAccessToken(payload) {
  44. const accessToken = await this.authenticator.getJwt({
  45. payload,
  46. expires: 60 * 3,
  47. })
  48. document.cookie = `siimee_access=${accessToken}; max-age=600; path=/; secure`
  49. },
  50. isHashInUrl(hash) {
  51. if (!hash) throw new Error('URL contains no hash!')
  52. },
  53. async doesEmailMatch(hashEmail) {
  54. const hashesMatch = await this.authenticator.verifyAuthEmail(
  55. hashEmail,
  56. )
  57. if (!hashesMatch) throw new Error('Hash is not in registry!')
  58. },
  59. async doesSessionTokenExist(sessionToken) {
  60. if (!sessionToken)
  61. throw new Error('sessionToken not in cookie store!')
  62. },
  63. async isSessionTokenValid(sessionToken) {
  64. const sessionTokenIsValid =
  65. await this.authenticator.validateSession(sessionToken)
  66. if (sessionTokenIsValid.error) {
  67. throw new Error(sessionTokenIsValid.error)
  68. } else {
  69. // TODO: Does accessToken need sessionToken data?
  70. await this.getAccessToken(...this.sessionToken)
  71. }
  72. },
  73. },
  74. }
  75. </script>
  76. <style>
  77. .wait-message {
  78. margin: 5rem auto;
  79. text-align: center;
  80. width: 90%;
  81. max-width: 35rem;
  82. font-size: 150%;
  83. font-weight: bold;
  84. }
  85. </style>