Metadata in React.js

I’m creating an application in which I want to send a metadata for the user logging in. How to send the metadata using loginWithRedirect() function in React.js. So, what all should I do to store the particular metadata for the user and excess it later when required. Help me with the procedure for react.js and Auth0 integration with sending and fetching of the Metadata.

Hey there, welcome to Auth0!

You can store user metadata in Auth0 user sub-object - user_metadata and request them when caling the loginWithRedirect().

The loginWithRedirect() function serves as a call to the Auth0’s /authorize endpoint (here, under “Authorize user”, you can check the parameters the request may take).

When working with react, in the index.js file, there are the authorizationParams (the /authorize request parameters) being specified. The relevant to user_metadata parameter is called “socpe”. Here is a sample code snipped under the index.js file including the user_metadata scope being requested by react app:

import React from 'react';
import { createRoot } from 'react-dom/client';
import { Auth0Provider } from '@auth0/auth0-react';
import App from './App';

const root = createRoot(document.getElementById('root'));

root.render(
  <Auth0Provider
    domain="{yourDomain}"
    clientId="{yourClientId}"
    authorizationParams={{
      redirect_uri: window.location.origin,
      audience: "https://{yourDomain}/api/v2/",
      scope: "read:current_user_metadata update:current_user_metadata"
    }}
  >
    <App />
  </Auth0Provider>
);

More about calling API with react can be found here.

Hope this helps - let us know!

This topic also can be helpful for you - Is it possible to modify a JWT and re-sign it from server side? - #3 by tyf

Yes it does. Thank you.

1 Like

Kindly help me in this as well.

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