# Autho nodejs login save to database

**URL:** <https://community.auth0.com/t/autho-nodejs-login-save-to-database/98310>\
**Category:** Get Help\
**Tags:** custom-database-connections, connections\
**Created:** [January 17, 2023, 7:03am UTC](https://community.auth0.com/t/autho-nodejs-login-save-to-database/98310 "2023-01-17T07:03:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![soorajlal](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/soorajlal/32/42726_2.png) [@soorajlal](https://community.auth0.com/u/soorajlal)\
**Post date:** [January 17, 2023, 7:03am UTC](https://community.auth0.com/t/autho-nodejs-login-save-to-database/98310/1 "2023-01-17T07:03:14Z")

</div>

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 🙏

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [January 18, 2023, 12:35am UTC](https://community.auth0.com/t/autho-nodejs-login-save-to-database/98310/3 "2023-01-18T00:35:02Z")

</div>

Hi @soorajlal,

Welcome to the Auth0 Community!

> [@soorajlal](#):
>
> 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?

For this, I recommend using a [Post-Login Action](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow) 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](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow/redirect-with-actions) to do so.

I hope this helps!

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

Thanks,  
Rueben

---

<div class="post-metadata">

**Author:** ![soorajlal](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/soorajlal/32/42726_2.png) [@soorajlal](https://community.auth0.com/u/soorajlal)\
**Post date:** [January 18, 2023, 4:59am UTC](https://community.auth0.com/t/autho-nodejs-login-save-to-database/98310/4 "2023-01-18T04:59:39Z")

</div>

```auto
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?

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [January 18, 2023, 9:00pm UTC](https://community.auth0.com/t/autho-nodejs-login-save-to-database/98310/5 "2023-01-18T21:00:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [February 1, 2023, 9:01pm UTC](https://community.auth0.com/t/autho-nodejs-login-save-to-database/98310/6 "2023-02-01T21:01:18Z")

</div>

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