# \[Express + Auth0\] I want to redirect to another backend endpoint after the callback

**URL:** <https://community.auth0.com/t/express-auth0-i-want-to-redirect-to-another-backend-endpoint-after-the-callback/190377>\
**Category:** Get Help\
**Tags:** login-experience, new-universal-login-experience\
**Created:** [August 8, 2025, 8:07pm UTC](https://community.auth0.com/t/express-auth0-i-want-to-redirect-to-another-backend-endpoint-after-the-callback/190377 "2025-08-08T20:07:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Isaacbfuents](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/isaacbfuents/32/76103_2.png) [@Isaacbfuents](https://community.auth0.com/u/Isaacbfuents)\
**Post date:** [August 8, 2025, 8:07pm UTC](https://community.auth0.com/t/express-auth0-i-want-to-redirect-to-another-backend-endpoint-after-the-callback/190377/1 "2025-08-08T20:07:59Z")

</div>

Hi,  
I’m building an application with:

- **Frontend:** React + Vite (localhost:5173)
- **Backend:** Express.js (localhost:3000)
- **Auth0:** Regular web app, using the dependancy “express-openid-connect”

My Auth0 configuration in the backend is:

```auto
const config = {
  authRequired: false,
  auth0Logout: true,
  secret: process.env.AUTH0_SECRET,
  baseURL: 'http://localhost:3000',
  clientID: process.env.AUTH0_CLIENT_ID,
  issuerBaseURL: process.env.AUTH0_DOMAIN,
}

app.use(auth(config));

```

Currently, after login, Auth0 sends me to the callback (`/callback`) and then automatically redirects to the `baseURL` (`http://localhost:3000/`).  
**What I want** is instead of sending me to `/`, to redirect me to another endpoint in my backend.

`http://localhost:3000/auth/session`

so I can create the user in my mongodb, generate access token and refresh token.

How can I make Auth0 automatically redirect to `http://localhost:3000/auth/session` after the callback instead of going to the `baseURL`?

---

<div class="post-metadata">

**Author:** ![gerald.czifra](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gerald.czifra/32/75301_2.png) [@gerald.czifra](https://community.auth0.com/u/gerald.czifra)\
**Post date:** [August 8, 2025, 9:03pm UTC](https://community.auth0.com/t/express-auth0-i-want-to-redirect-to-another-backend-endpoint-after-the-callback/190377/3 "2025-08-08T21:03:55Z")

</div>

Hi @Isaacbfuents

Welcome to the Auth0 Community!

I believe that what you’re currently missing in order to achieve your desired flow would be the `afterCallback` hook, which is provided by the `express-openid-connect` library ( please see the following [documentation](https://github.com/auth0/express-openid-connect/blob/master/EXAMPLES.md) ).

You should be able to define it within your existing code similarly to this:

```auto
const config = {
  authRequired: false,
  auth0Logout: true,
  secret: process.env.AUTH0_SECRET,
  baseURL: 'http://localhost:3000',
  clientID: process.env.AUTH0_CLIENT_ID,
  issuerBaseURL: process.env.AUTH0_DOMAIN,
  routes:
  auth({
    afterCallback: (req, res, session) => {
      const claims = jose.JWT.decode(session.id_token); // using jose library to decode JWT
      if (claims.org_id !== 'Required Organization') {
        throw new Error('User is not a part of the Required Organization');
      }
      return session;
    },
  })

}

app.use(auth(config));

```

Additional resources on the `afterCallback` hook :

- [Pass token from afterCallback to returnTo URL](https://community.auth0.com/t/pass-token-from-aftercallback-to-returnto-url/153042)
- [Do you need to verify the ID token in afterCallback?](https://community.auth0.com/t/do-you-need-to-verify-the-id-token-in-aftercallback/77172)

Let us know if this helped solve your issue!

Best regards,  
Gerald

---

<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:** [August 22, 2025, 9:04pm UTC](https://community.auth0.com/t/express-auth0-i-want-to-redirect-to-another-backend-endpoint-after-the-callback/190377/4 "2025-08-22T21:04:54Z")

</div>

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