# Why is my passport-auth0 code causing an infinite redirect

**URL:** <https://community.auth0.com/t/why-is-my-passport-auth0-code-causing-an-infinite-redirect/69548>\
**Category:** Get Help\
**Created:** [September 13, 2021, 4:18pm UTC](https://community.auth0.com/t/why-is-my-passport-auth0-code-causing-an-infinite-redirect/69548 "2021-09-13T16:18:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgleason](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jgleason/32/25904_2.png) [@jgleason](https://community.auth0.com/u/jgleason)\
**Post date:** [September 13, 2021, 4:18pm UTC](https://community.auth0.com/t/why-is-my-passport-auth0-code-causing-an-infinite-redirect/69548/1 "2021-09-13T16:18:08Z")

</div>

I have the following routes…

```auto
router.route("/").get(passport.authenticate("auth0", {
    scope: "openid email profile",
  }), api.hello);
router.get("/callback", (req, res, next)=>{
    passport.authenticate("auth0", {
      scope: "openid email profile",
    }, (err, user, info) => {
      if (err) return next(err);
      if (!user) return res.redirect("/login");
      req.logIn(user, (err) => {
        if (err) return next(err);
        res.redirect("/");
      });
    })(req, res, next);
  });

```

But when I run I get the login page and then I get /callback redirecting back to / which redirects back to callback. I am basically following the steps here ([Node.js and Express Tutorial: Authentication Using Passport](https://auth0.com/blog/create-a-simple-and-secure-node-express-app/#Set-Up-Real-World-Authentication-for-Node-js))

What am I missing?

---

<div class="post-metadata">

**Author:** ![jgleason](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jgleason/32/25904_2.png) [@jgleason](https://community.auth0.com/u/jgleason)\
**Post date:** [September 13, 2021, 6:26pm UTC](https://community.auth0.com/t/why-is-my-passport-auth0-code-causing-an-infinite-redirect/69548/2 "2021-09-13T18:26:35Z")

</div>

I changed to passport-auth0-openidconnect and now it is working as expected

---

<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:** [September 28, 2021, 6:27pm UTC](https://community.auth0.com/t/why-is-my-passport-auth0-code-causing-an-infinite-redirect/69548/3 "2021-09-28T18:27:28Z")

</div>

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