# Error during parseHash: Cannot read properties of undefined (reading 'alg')

**URL:** <https://community.auth0.com/t/error-during-parsehash-cannot-read-properties-of-undefined-reading-alg/97838>\
**Category:** Get Help\
**Tags:** authentication, login, auth0\
**Created:** [January 10, 2023, 12:34pm UTC](https://community.auth0.com/t/error-during-parsehash-cannot-read-properties-of-undefined-reading-alg/97838 "2023-01-10T12:34:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cjohnson](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cjohnson/32/39450_2.png) [@cjohnson](https://community.auth0.com/u/cjohnson)\
**Post date:** [January 10, 2023, 12:34pm UTC](https://community.auth0.com/t/error-during-parsehash-cannot-read-properties-of-undefined-reading-alg/97838/1 "2023-01-10T12:34:22Z")

</div>

In Cypress, I’m working on our programmatic login functionality, and I’m at the final step:

Routing the application to a URL with the proper hash so our auth0 integration can parse `window.location.hash` → `handleAuthentication` → `setSession` in the created hook (using `auth0.js`. However, during `handleAuthentication`, `parseHash` is throwing the following error: `TypeError: Cannot read properties of undefined (reading 'alg')`. What’s strange is the log “insidepromise” fires, but “insideparshhash” does not, yet, I’m positive this is where the error is coming from. Here is the format of the URL I’m visiting via Cypress: `const callbackUrl = '${Urls.APP_URL}/#access_token=${access_token}&scope=openid%20%profile%20%email&id_token=${id_token}&expires_in=${expires_in}&token_type=Bearer&state=${auth0State.state}'` (ignore ’ with the string literal).

```auto
at auth0.min.esm.js:8:169459
    at auth0.min.esm.js:8:170685
    at push../node_modules/auth0-js/dist/auth0.min.esm.js.I.verify (auth0.min.esm.js:8:127349)
    at push../node_modules/auth0-js/dist/auth0.min.esm.js.WebAuth.validateToken (auth0.min.esm.js:8:170641)
    at push../node_modules/auth0-js/dist/auth0.min.esm.js.WebAuth.validateAuthenticationResponse (auth0.min.esm.js:8:168446)
    at push../node_modules/auth0-js/dist/auth0.min.esm.js.WebAuth.parseHash (auth0.min.esm.js:8:166511)
    at auth0Plugin.js:183:24
    at new Promise (<anonymous>)
    at Vue.handleAuthentication (auth0Plugin.js:181:16)
    at Vue.created (auth0Plugin.js:76:22)

```

```auto
      async handleAuthentication () {
        this.loading = true

        return new Promise((resolve, reject) => {
          console.log('insidepromise')
          this.webAuth.parseHash((error, authResult) => {
            console.log('insideparsehash')
            if (error || (!authResult || !authResult.idToken)) {
              this.error = error

              ...

              return reject(error)
            }
            resolve(authResult)
          })
        }).then(async (authResult) => {
          await this.setSession(authResult)
          this.loading = false
        })
      },

```

---

<div class="post-metadata">

**Author:** ![cjohnson](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cjohnson/32/39450_2.png) [@cjohnson](https://community.auth0.com/u/cjohnson)\
**Post date:** [January 10, 2023, 3:33pm UTC](https://community.auth0.com/t/error-during-parsehash-cannot-read-properties-of-undefined-reading-alg/97838/2 "2023-01-10T15:33:16Z")

</div>

I’ve been doing a bit of digging, and I BELIEVE the error comes from lines 448-450 of the `WebAuth.prototype.validateAuthenticationResponse` function in web-auth/index.js.

```auto
      // if the alg is not HS256, return the raw error
      if (decodedToken.header.alg !== 'HS256') {
        return callback(validationError);
      }

```

What I don’t understand is where the `header.alg` value comes from, because it’s not a value available when you redirect from the auth0 login page when using our application.

---

<div class="post-metadata">

**Author:** ![cjohnson](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cjohnson/32/39450_2.png) [@cjohnson](https://community.auth0.com/u/cjohnson)\
**Post date:** [January 10, 2023, 3:37pm UTC](https://community.auth0.com/t/error-during-parsehash-cannot-read-properties-of-undefined-reading-alg/97838/3 "2023-01-10T15:37:47Z")

</div>

Solved it - I didn’t have `scope` set in my request to authenticate programmatically, so it wasn’t returning an `id_token`.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [January 24, 2023, 3:38pm UTC](https://community.auth0.com/t/error-during-parsehash-cannot-read-properties-of-undefined-reading-alg/97838/4 "2023-01-24T15:38:28Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
