I’m trying to send custom information from Auth0 SDK in React app during the registration.
loginWithRedirect (with its options) is called when the React app doesn’t have any user authenticated on Auth0 SDK. Then I use this method to sign up the user and I’m trying to send custom information to Auth0 Rules:
SOLUTION:
My Reac app use this code to redirect the unregistered user for signing up with loginWithRedirect. I pass some options to this method:
appState (to redirect the user on the React app after the registration, it needs more code to make the redirection on the app; I recommend to check the SPA sample by Auth0).
customLogin: it’s my custom information the the Rule will get.
You can watch on the photo the options for loginWithRedirect (Authorization Server is in Auth0, and Rules are also in it). The key is to read that you can add your custom parameter:
await loginWithRedirect({
appState: {
// Used to redirect to an specific url after the signup.
targetUrl: path
},
customLogin: 'agent'
});
Then, after the user has registered, the Rule is called.
async function myRule(user, context, cb) {
...
}
The Rule has a context object with request → query object. The query contains your custom data (in my case is customLogin) that was passed before via loginWithRedirect.