Show only user content in app

I’m using Auth0 in a Vue app and so far the authentication works fine. However, now I need to be able to show user-related content on a certain URL. For example, if a user purchases an item from the shop, I need to display only the items bought by him on his profile. How can I implement this in a JS application?

Hey @ygspasov,

Once you have authentication enabled in your Vue.js app, you need to setup an API to have the user access their info most likely stored in a backend. Here’s how.

Let us know if that works for you!

Hi @mauricio,

I don’t use Express for a backend. It is beyond the scope of what I’m doing. I use JsonServer and Axios, and I store all data in a JSON file. Perhaps if you tell me how to extract user ID or email after logging to the app with Auth0, this will be enough for my needs.

It depends on how you’ve implemented the auth logic. If you followed our quickstart, you should be able to get the user’s email by using $auth.user.email.

By downloading the sample code of the quickstart, you can see that src/auth/auth/authWrapper.js attaches the Auth0 instance to Vue.prototype.$auth.

2 Likes

That’s what I needed. I just accessed the email in a Vue component with:

data() {
    return {
      email: this.$auth.user.email
    };
  }

Thank you!

2 Likes

Great to know you were able to solve the issue! Thanks for sharing.

1 Like

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