Auth0 Admin Role

Sorry for the re-post - I deleted the previous post because the formatting was off, and it would not allow me to edit the question…

I have implemented Auth0 for use in our platform, and I am creating “roles” to assign to particular users. For now, I want to only create an “admin” role and assign it to users. The aim is so that I only want these particular “admins” to be able to have the ability to either view or click the “Answer” button on our forum page.

Below, is some of the code for the forum page…

return (
        {/* Table of questions - with option to answer
      using bootstrap 'Table' component */}
        <Table striped bordered hover variant='dark' responsive>
              <th>Asked by</th>
              <th>Display Answers</th>
            {/* within the table, take array  */}
            { => {
              return (
                <tr key = {question._id}>
                  <td><Button onClick={() => this.handleClickPostAnswer(question._id, question.questionText)}>Answer</Button></td>
                  <td><Button onClick={() => this.handleClickReadAnswers(question._id)}>Display</Button></td>
          {/* renders AnswersModal if this.state.displayAnswers is true */}
          <AnswersModal show={this.state.displayAnswers}/>

Below is the line of code that creates the Answer button. I only want this visible or be able to be clicked on for admins which I will assign as roles in Auth0.

<td><Button onClick={() => this.handleClickPostAnswer(question._id, question.questionText)}>Answer</Button></td>

Is anyone able to suggest the best way of doing this, or point me towards a resource that could help with this? Do I need to perhaps instead of roles, create rules on Auth0?


Hi @jkm151997!

For just visibility of an element, you could use a similar method to here to add logic for rendering different items based on the returned user profile -

To get the roles into the user object, you would need to also add a rule like this:

You could then check for a certain role and render conditionally, here is a basic example based on the Profile.js view in the Auth0 React quickstart, in this case I set my custom namespace to be, but this can be any non auth0 domain and is just for avoiding name collisions and won’t be actually called by Auth0:

import React from "react";
import { Container, Row, Col } from "reactstrap";

import Highlight from "../components/Highlight";
import Loading from "../components/Loading";
import { useAuth0, withAuthenticationRequired } from "@auth0/auth0-react";

export const ProfileComponent = () => {
  const { user } = useAuth0();
  const userRoles = user && user[""];
  const userHasAccess = userRoles.some(function (role) {
    return "React Admin" === role;

  return (
    <Container className="mb-5">
      <Row className="align-items-center profile-header mb-5 text-center text-md-left">
        <Col md={2}>
            className="rounded-circle img-fluid profile-picture mb-3 mb-md-0"
        <Col md>
          <p className="lead text-muted">{}</p>
        <Highlight>{JSON.stringify(user, null, 2)}</Highlight>
          {userHasAccess &&
          <h2>User has access</h2>}

export default withAuthenticationRequired(ProfileComponent, {
  onRedirecting: () => <Loading />,

However as this is a SPA, a savvy user could still find the button, so ideally any sensitive content/functions would be behind a backend API, which would in turn validate the user’s access token for the correct roles/permissions before allowing them to actually ‘answer’.