Hiho,
I followed this guide here: https://auth0.com/blog/next-js-authentication-tutorial/ (adding auth with passport to next.js)
I have one simple problem.
In my "/login" Link from next.js when I click it, I can see this error for about 200ms:
Request URL: http://localhost:3000/_next/static/development/pages/login.js Request Method: GET Status Code: 404 Not Found
Then it automatically redirects to the root of the Homepage since it is then authenticated successfully (with passport facebook).
Still I'm asking why do I see this error for a brief moment?
Here is the client Link:
{!user && (
<Link href="/login">
<a>Log In</a>
</Link>
)}
And here are the server routes:
router.get("/login", passport.authenticate("facebook"));
router.get("/callback", (req, res, next) => {
passport.authenticate("facebook", (err, user) => {
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);
});
What is triggering this error?
My guess:
Because I use "Link" Component from next.js the app tries to find a page that's name is "Login.js" . Since it's not existent because it's just a server api it shows that error. If I'm right, how to get rid of it? Thx guys!
What have I tried so far:
I just found this in their docs: https://github.com/zeit/next.js/#disabling-file-system-routing
But that breaks the app, since it cant resolve any pages anymore. So that's not it I guess :D
if (!user) return res.redirect("/login");
– evgeni fotiaif (!req.isAuthenticated()) return res.redirect("/login");
what about this line – evgeni fotia