Autho nodejs login save to database

Hi folks,
I have a nodejs based appllcation where I integrated auth0 login. I want to save loggedin user details in my own database. My question is, when user hits URL/login and authorize it with app, Can I redirect to my another route and save fetched user info in my database?

Please help me. Thanks in advance :pray:

Hi @soorajlal,

Welcome to the Auth0 Community!

For this, I recommend using a Post-Login Action to make a request to save the logged-in user details to your database. This way the user details are saved programmatically every time the user logs in.

But if you prefer to redirect the users to another route, I recommend using a Redirect Action to do so.

I hope this helps!

Please let me know if there’s anything else I can do to help.

Thanks,
Rueben

const { auth } = require('express-openid-connect');
const request = require('request');

const config = {
  authRequired: false,
  auth0Logout: true,
  baseURL: BASE_URL,
  clientID: CLIENT_ID,
  issuerBaseURL: ISSUER_BASE_URL,
  secret: SECRET,
  authorizationParams: {
    // Note: you need to provide required parameters if this object is set.
   //  response_type: "id_token",
    //  response_mode: "form_post",
    scope: "openid profile email"
  },
  afterCallback: async (req, res, session, state) => {
    const userProfile = await request(`${ISSUER_BASE_URL}/userinfo`);
    console.log("userProfile-------------", userProfile)
    return {
      ...session,
      userProfile // access using `req.appSession.userProfile`
    };
  }
};

app.use(auth(config));

This is my code. Whether I can retrieve user profile inside aftercallback function?

Hi @soorajlal,

Yes, you can use the /userinfo endpoint to get the authenticated user profile.

Please let me know if you have any further questions.

Thanks,
Rueben

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