# Auth0 redirect after login issue

**URL:** <https://community.auth0.com/t/auth0-redirect-after-login-issue/48167>\
**Category:** Get Help\
**Created:** [August 17, 2020, 8:23pm UTC](https://community.auth0.com/t/auth0-redirect-after-login-issue/48167 "2020-08-17T20:23:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![trevordammon](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/trevordammon/32/13337_2.png) [@trevordammon](https://community.auth0.com/u/trevordammon)\
**Post date:** [August 17, 2020, 8:23pm UTC](https://community.auth0.com/t/auth0-redirect-after-login-issue/48167/1 "2020-08-17T20:23:04Z")

</div>

Hi all,

I am trying to set up a node.js server with express for the backend authentication of my React App. On the front end I have an `<a>` routing users to [http://localhost:3001/login](http://localhost:3001/login). My /login route runs fine and the user can login.

```auto
router.get('/login', passport.authenticate('auth0', {
	scope: 'openid email profile'
}), (req, res) => {
	res.redirect('/');
});

```

After login the user is routed to [http://localhost:3000/callback?code=OXVrD51HyqKA&state=g6Fo2SBJM2RGNjc1FWdU8#](http://localhost:3000/callback?code=OXVrD51HyqKA&state=g6Fo2SBJM2RGNjc1FWdU8#)

or some similar url with different query parameters. I don’t have a specified front-end route with “/callback” and I am assuming I don’t need one. It seems like my back-end “/callback” route should be running and rerouting me again but it is not.

```auto
router.get('/callback', function (req, res, next) {
	console.log('called')
	passport.authenticate('auth0', function (err, user, info) {
		if (err) {
			return next(err);
		}
		if (!user) {
			return res.redirect('/login');
		}
		req.logIn(user, function (err) {
			if (err) {
				return next(err);
			}
			const returnTo = req.session.returnTo;
			delete req.session.returnTo;
			res.redirect(returnTo || '/user');
		});
	})(req, res, next);
});

```

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 17, 2020, 9:36pm UTC](https://community.auth0.com/t/auth0-redirect-after-login-issue/48167/2 "2020-08-17T21:36:51Z")

</div>

Hi @trevordammon,

Is the problem that the callback is on a different port? 3000 v 3001?

---

<div class="post-metadata">

**Author:** ![trevordammon](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/trevordammon/32/13337_2.png) [@trevordammon](https://community.auth0.com/u/trevordammon)\
**Post date:** [August 17, 2020, 10:58pm UTC](https://community.auth0.com/t/auth0-redirect-after-login-issue/48167/3 "2020-08-17T22:58:04Z")

</div>

That looks like it fixes the initial problem. However now after the callback function runs it is routing me to localhost:3001/users not localhost:3000/users.

I will see if I can play around with this and find a solution.

Thanks Dan!

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [August 18, 2020, 3:38pm UTC](https://community.auth0.com/t/auth0-redirect-after-login-issue/48167/4 "2020-08-18T15:38:04Z")

</div>

Let me know if you figure it out!

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [September 2, 2020, 3:43pm UTC](https://community.auth0.com/t/auth0-redirect-after-login-issue/48167/5 "2020-09-02T15:43:28Z")

</div>

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