I am using Auth0's provided login and sign-up screen (https://auth0.com/docs/quickstart/webapp/nextjs/01-login#add-login-to-your-application) for my application. I set up a callback after signup where I create a profile in my DB with the email as the primary key.
The issue I'm running into is that on my home screen, I have a button that says "Sign up as admin" and another "Sign up as a user". How do I pass into this Auth0 sign up screen whether the user click "user" or "admin" so that in the callback I can create the profile with "user" or "admin"?
You can add a state param to the /authorize request to maintain state between request and callback.
In Auth0, you if you need to discriminate between "user" or "admin", you could extract the state param specified the /authorize request from the context object (context.request to be specific) - see here for context object properties in Auth0 rules.
You do not determine signup as admin or user on the front end, this is done in backend. In auth0 authentication you add rules in auth) dashboard. When you sign in auth0, you can either select a rule template or you can create your own:
an example of script:
function (user, context, callback) {
user.app_metadata = user.app_metadata || {};
// You can add a Role based on what you want
// In this case I check email
//***** DETERMINE ADMINS HERE *******
var addRolesToUser = function(user, cb) {
if (user.email === "Email@email.com") {
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);
});
}
});
}