| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <template lang="pug">
- .wait-message
- p.verify-message Thanks for authenticating your email!
- p.verify-message Please give us a moment to redirect you back to the survey
- </template>
-
- <script>
- // NOTE: If the httponly flag is to be used with these cookies,
- // this file will need to be rewritten as an .html file due to the way
- // that Hapi sets cookies via the h.state() method
- import { Authenticator } from '../services/auth.service.js'
- export default {
- name: 'VerifyView',
- data: () => ({
- authenticator: {},
- answers: {},
- }),
- async created() {
- this.authenticator = new Authenticator()
- const hashEmail = this.$route.params.email
-
- // TODO: generate a token on the backend here and have it sent over in
- // the headers intead of setting it directly with document.cookie (see note above)
-
- const hashesMatch = await this.authenticator.verifyAuthEmail(hashEmail)
- const siimeeToken = this.grabToken(document.cookie)
-
- // TODO: Then send this token and receive a different token
- const jwt = await this.authenticator.validateJwt(siimeeToken)
- this.answers = jwt.payload
- const accessToken = await this.generateAccessToken()
- if (jwt.isValid && hashesMatch) {
- const siimeeAnswers = JSON.stringify(this.answers)
- document.cookie = `siimee_answered=${siimeeAnswers}; max-age=360 ; path=/onboarding; secure`
- document.cookie = `siimee_session=${siimeeToken} ; max-age=360 ; path=/onboarding; secure`
- document.cookie = `siimee_access=${accessToken}; max-age=360 ; path=/onboarding; secure`
- this.$router.push('/onboarding')
- }
- // else {
- // render ERROR message above or redirect to 404 (or both?)
- },
- methods: {
- grabToken(cookieString) {
- const cookies = cookieString.split('; ').reduce((prev, current) => {
- const [name, ...value] = current.split('=')
- prev[name] = value.join('=')
- return prev
- }, {})
- return 'siimee_jwt' in cookies ? cookies['siimee_jwt'] : undefined
- },
- async generateAccessToken() {
- const accessJwt = await this.authenticator.generateJwt({
- ...this.answers,
- expiration: 60 * 3, // testing for now... extend to 1 hour?
- })
- return accessJwt
- },
- },
- }
- </script>
-
- <style>
- .wait-message {
- margin: 5rem auto;
- text-align: center;
- width: 90%;
- max-width: 35rem;
- font-size: 150%;
- font-weight: bold;
- }
- </style>
|