Provide arguments for Auth0 registration

Incorporating Auth0's provided login and sign-up screen (check it out at https://auth0.com/docs/quickstart/webapp/nextjs/01-login#add-login-to-your-application) into my application has been a seamless process. Upon signup, I have implemented a callback function that creates a profile in my database using the email as the primary key.

However, I've encountered an obstacle on my home screen where there are two buttons: one for "Sign up as admin" and another for "Sign up as a user". My question is, How can I pass information to the Auth0 sign-up screen indicating whether the user clicked "user" or "admin", so that in the callback function I can appropriately create the profile as either "user" or "admin"?

Answer №1

To preserve data between a request and callback, consider including a state parameter in the /authorize request.

If you want to differentiate between "user" and "admin" roles using Auth0, extract the state parameter from the context object (specifically context.request) included in the /authorize request - check out the available context object properties for Auth0 rules here.

Answer №2

The determination of whether to sign up as an admin or user is not done on the front end, but rather in the backend. In terms of auth0 authentication, you can incorporate rules within the auth0 dashboard. Upon signing into auth0, you have the option to choose a rule template or generate your own:

https://i.sstatic.net/A9ByW.png

Here is an example of a script:

function (user, context, callback) {
  user.app_metadata = user.app_metadata || {};
  // You can assign roles based on your preference
  // In this scenario, email is used for verification
  //***** ADMINS ARE DECIDED HERE *******
  var addRolesToUser = function(user, cb) {
    if (user.email === "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c580a8a4aca985a0a8a4aca9eba6aaa8">[email protected]</a>") {
      cb(null, ['admin']);
    } else {
      cb(null, ['guest']);
    }
  };

  addRolesToUser(user, function(err, roles) {
    if (err) {
      callback(err);
    } else {
      user.app_metadata.roles = roles;
      auth0.users.updateAppMetadata(user.user_id, user.app_metadata)
        .then(function(){
          context.idToken[NAMESPACE] = user.app_metadata.roles;
          context.accessToken[NAMESPACE] = user.app_metadata.roles;
          callback(null, user, context);
        })
        .catch(function(err){
          callback(err);
        });
    }
  });
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Additional headers are included in the Access-Control-Request-Headers

I have been struggling to include a customized header in my angular js GET request like so: $http({ method : 'GET', url : s, headers : { "partnerId" : 221, "partnerKey" : "heeHBcntCKZwVsQo" } ...

JS/Docker - The attribute 'user' is not recognized in the context of 'Session & Partial<SessionData>'

I'm attempting to integrate express-session into my Node.js application running within Docker. I've come across several discussions on the topic: Express Session: Property 'signin' does not exist on type 'Session & Partial<Se ...

Prisma: Incorrectly identifying existing items where the list contains any of the specified items

Within my Prisma model, I have a property designated to store a list of phone numbers in the format phones String[] @unique When making an API call with a model that may include one or more phone numbers, my goal is to locate any existing record where any ...

AngularJS Skype URI Button Problem

Implementing a Skype button in my project using AngularJS has been challenging. Here is the code I am currently working with: HTML: <script type="text/javascript" src="http://www.skypeassets.com/i/scom/js/skype-uri.js"></script> <skype-ui ...

Adding an attribute to the last item of an Angular / NGX Bootstrap component

I am working with a dynamic list that utilizes NGX Bootstrap Dropdowns to showcase 4 sets of dropdown lists. However, the Dropdowns in the final list are getting obscured off-page. Thankfully, NGX Bootstrap offers a solution in the form of a dropUp option ...

Implementing AngularJS drag and drop functionality in a custom directive

I am in search of an example that demonstrates similar functionality to the HTML5 File API using Angular-js. While researching directives for Angular 1.0.4, I found outdated examples that heavily rely on DOM manipulation. Here is a snippet of the pure Ja ...

What is the best way to implement a JavaScript pattern matching for both "aaaa" and "aaa aaa"?

Can anyone help me create a pattern that can accept both strings with spaces and without spaces in the same text box? I would appreciate any guidance on how to achieve this. Thanks! ...

The ElementNotVisibleException error was triggered because the element is currently hidden from view, making it unable to be interacted with through the command

I'm facing an issue when trying to clear the text box. The error message I am receiving is: org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with Command duration or timeout: 30.14 se ...

Angular JavaScript can be utilized for JSON date formatting

I am having trouble displaying JSON data in an HTML table. When I run my file, the date appears as '2018-11-21T00:00:00.000+0000' in the table. However, I only want to display '2018-11-21'. Can someone help me figure out how to split it ...

What is the best way to integrate properties subsets into your classes?

In my code, I am working with 3 classes ... class1 { constructor(a, b, c) { this.a = a; this.b = b; this.c = c; this.toClass2 = function() { // TODO: return this as an instance of class2; // the conversion would remove the un ...

The AJAX function is failing to return false

I found this code snippet in my index.html file: <form> <input onkeyup="firstnamecheck(this.value)" type="text" name="firstname" id="Start" class="Inputs" /> <button type="submit" name="Murad" id="tester" title="Register">Register</b ...

Dynamic Line Animation with React Three Fiber

Is it possible to create a similar effect like the one showcased on this website: I'm looking to incorporate a dashed moving line that indicates direction. I prefer to use r3f, but regular three.js would also work. The background design is also app ...

Looking for guidance on implementing a straightforward nested for loop in a Node.js environment

I am facing an issue with my code that is meant to generate a 10x10 grid. Since transitioning to Node.js, I am struggling to make it work correctly due to my synchronous thinking pattern. Currently, the Y values are being assigned directly to 10 for all X ...

When going through an array using jquery, only the final object is returned

I am diving into the world of jQuery and dealing with what seems to be a basic issue. <input type="text" name="text1" value=""></input> <input type="text" name="text2" value=""></input> <input type="text" name="text3" value=""&g ...

Angular: Leveraging real-time data updates to populate an Angular Material Table by subscribing to a dynamic data variable in a service

Seeking guidance on how to set up a subscription to a dynamic variable (searchData - representing search results) for use as a data source in an Angular Material Table. I have a table-datasource.ts file where I want to subscribe to the search results from ...

The suspense fallback fails to display when the router.refresh() function is utilized

Whenever the RefreshBtn component is clicked, all other components rerender with updated data. However, the suspense fallback does not display as intended. This is my page.jsx: const Home = () => { return( <RefreshBtn /> <Suspense f ...

Reading a glTF file from the local system onto Javascript's memory

Currently, I am working on developing a native iOS and Android application using three.js and Capacitor. One of the challenges I am facing is loading GLTF models from an asset folder that is bundled with the code and delivered to the user. I am unsure abou ...

Gridsome's createPages and createManagedPages functions do not generate pages that are viewable by users

Within my gridsome.server.js, the code snippet I have is as follows: api.createManagedPages(async ({ createPage }) => { const { data } = await axios.get('https://members-api.parliament.uk/api/Location/Constituency/Search?skip=0&take ...

Error in AJAX call while attempting to decrypt plain text using Crypto-JS

I recently integrated Crypto-JS plain text encryption/decryption into my NodeJS application. Testing the code on the server-side showed that everything worked perfectly: var encrypted_string = CryptoJS.AES.encrypt(input_string, '123Key'); var ...

Retrieve data from a variable that is located within a function that is also

<script> const tally ={ total: 0, increase: function(){ total++; console.log(total); } } const selectBtn = document.getElementsByTagName('button& ...