# Validating token with back node js + front vue 3

**URL:** <https://community.auth0.com/t/validating-token-with-back-node-js-front-vue-3/124159>\
**Category:** Get Help\
**Tags:** new-universal-login-experience, login-experience\
**Created:** [January 4, 2024, 1:50pm UTC](https://community.auth0.com/t/validating-token-with-back-node-js-front-vue-3/124159 "2024-01-04T13:50:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gerarca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gerarca/32/52802_2.png) [@Gerarca](https://community.auth0.com/u/Gerarca)\
**Post date:** [January 4, 2024, 1:50pm UTC](https://community.auth0.com/t/validating-token-with-back-node-js-front-vue-3/124159/1 "2024-01-04T13:50:14Z")

</div>

hello!!! I have this middleware on my back:

```auto
const { auth } = require("express-oauth2-jwt-bearer");
import { env } from "../../utils/enviroment";

export const validateAccessToken = auth({
  issuerBaseURL: `https://${env.AUTH0_DOMAIN}`,
  audience: env.AUTH0_AUDIENCE,
})

```

and I have this middleware too:

```auto
//file server.js
app.use(errorHandler);
app.use(notFoundHandler);

```

following this example:  
`https://github.com/auth0-developer-hub/api_express_javascript_hello-world`

and in my front(Vue js 3) I have:

```auto
<template>
  <div class="content-layout" :v-if="invalidUser">
    <h1 id="page-title" class="content__title">Warning</h1>
    <div class="content__body">
      <p id="page-description">
        <span>You are <strong>Blocked</strong>.</span>
        <span><strong >Only authorized users can access this platform.</strong></span>
      </p>
      <div class="profile-grid" >
          <button class="button__cancel" @click="goHome" style="">Go home</button>
      </div>
    </div>
  </div>  
</template>

<script>

import { checkUserLogged } from "../services/message.service";

export default {
  data() {
    return {
      user: this.$auth0.user,
      invalidUser: false
    };
  },
  computed: {
  },
  methods: {
    async checkUser() { 
      if(this.user.name){
        const accessToken = await this.$auth0.getAccessTokenSilently();
        const user = this.user;
        const { data, error } = await checkUserLogged(accessToken, user);
        if (data) { 
          if( data.authorize ){
            this.$router.push('/profile');
          }else{
            this.invalidUser = true; 
            setTimeout(async () => {
              await this.$auth0.logout({
                logoutParams: {
                  returnTo: 'http://localhost:4040/',
                }
              });
            }, 5000);                   
          }
        }
        if (error) {
          this.message = JSON.stringify(error, null, 2);
        }        
      }
    },
    goHome(){
      this.$auth0.logout({
        logoutParams: {
          returnTo: 'http://localhost:4040/',
        }
      });      
      this.$router.push('/');
    }
  },
  mounted() { 
    this.checkUser();
  },
};
</script>

```

I’m getting this issue:

```auto
401 Unauthorized
message:"Bad credentials"

```

I checked my enviroment: CLIENT\_ORIGIN\_URL, AUTH0\_AUDIENCE, AUTH0\_DOMAIN, AUTH0\_CLIENT\_ID and AUTH0\_CLIENT\_SECRET, in my back and front code, and it’s right, you can help me? what’s wrong

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [January 4, 2024, 7:52pm UTC](https://community.auth0.com/t/validating-token-with-back-node-js-front-vue-3/124159/3 "2024-01-04T19:52:38Z")

</div>

Hi @Gerarca,

Thanks for reaching out to the Auth0 Community!

I understand that you are trying to validate your access token and encountered the `401 Unauthorized` error, specifically mentioning about having bad credentials.

Now, could you please check your [Logs](https://manage.auth0.com/#/logs) for the error and verify that the data passed in the request is correct (e.g client\_id, audience, etc)?

The error logs should provide you details about the data your passed in your request.

And if possible, could you decode your access token and verify the payload is correct as well?

(Reference: [Auth0 Node (Express) API SDK Quickstarts: Authorization](https://auth0.com/docs/quickstart/backend/nodejs/01-authorization#configure-the-middleware))

Please let me know how this goes for you.

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![Gerarca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gerarca/32/52802_2.png) [@Gerarca](https://community.auth0.com/u/Gerarca)\
**Post date:** [January 5, 2024, 12:15am UTC](https://community.auth0.com/t/validating-token-with-back-node-js-front-vue-3/124159/4 "2024-01-05T00:15:00Z")

</div>

Hello @rueben.tiow

I was checking the monitor logs and it look like everything is ok:

 ![Screenshot 2024-01-04 201311](https://global.discourse-cdn.com/auth0/original/3X/1/9/192e0bf297972fbd8a2abc7a64e737d021c6c2f2.png)

I’m using this [configuration](https://auth0.com/docs/quickstart/backend/nodejs/01-authorization#configure-the-middleware), in my back(node js)

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [January 5, 2024, 9:19pm UTC](https://community.auth0.com/t/validating-token-with-back-node-js-front-vue-3/124159/5 "2024-01-05T21:19:35Z")

</div>

Hi @Gerarca,

Thanks for your response.

Looking at your logs, it seems like the user was able to login and exchange the authorization code for an access token.

Could you try decoding the access token on [jwt.io](http://jwt.io) and see if the payload is correct?

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![Gerarca](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gerarca/32/52802_2.png) [@Gerarca](https://community.auth0.com/u/Gerarca)\
**Post date:** [January 6, 2024, 12:40am UTC](https://community.auth0.com/t/validating-token-with-back-node-js-front-vue-3/124159/6 "2024-01-06T00:40:07Z")

</div>

Hi @rueben.tiow

 ![s](https://global.discourse-cdn.com/auth0/original/3X/7/1/71874f71e3cce7c3f57b0911b4bd965065ce92d6.png)

I got the “iss” correct, but on “PAYOLAD: DATA” I got nothing, this is bad??

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [February 16, 2024, 6:42pm UTC](https://community.auth0.com/t/validating-token-with-back-node-js-front-vue-3/124159/7 "2024-02-16T18:42:53Z")

</div>

Hi @Gerarca,

It seems that the token is an opaque access token.

In this case, please check that your login request passes in the `audience` parameter to get a JWT access token.

Cheers,  
Rueben

---

<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:** [March 1, 2024, 6:43pm UTC](https://community.auth0.com/t/validating-token-with-back-node-js-front-vue-3/124159/8 "2024-03-01T18:43:31Z")

</div>

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