How do I get User Metadata in the Login

Please include the following information in your post:

  • SDK Verion: express-openid-connect: “^2.5.1”,
    *Platform Version: NodeJs 16.6.2

I am using nodejs and express openid connect and I am trying to get ALL of the user the metadata from auth0.

here’s the route:

const authenticationController = require("../controllers/auth.controller");
const { auth, requiresAuth } = require('express-openid-connect');

module.exports = function(app, cors, corsOptions) {
        function (req, res, next) {
            authenticationController.GetAuthentication( req, res, next );

here’s the controller:

exports.GetAuthentication = async ( req, res, next ) => {
    try {
        var user = req.oidc.user;
        return res.status(200).json(user);
     } catch(err) {
       return next(err)

Here is the output:

,"name":"First Last",

As you can see none of the metadata for my user is showing up in the user object. How do I get the metadata?

Hey @solid,

The reason you didn’t receive the user’s metadata is because metadata is not a standard claim so it will not be included in ID Tokens by default.

To include it, you must write a Rule to copy user_metadata properties to the ID token. This is explained in detail here: Add custom claims to a token. I hope this helps.

More information:

1 Like

Thanks for helping on this one Ale!