Gatsby Private Route not working as intended #31861
Unanswered
purnimagupta
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I'm trying to implement a blog with gated content using Gatsby as the front-end and Strapi as the CMS for authentication. Have been following the instructions from the official Gatsby docs on client-only routes and user authentication.
I want to make the following URLs private:
/app/articles
: This is the articles list pageapp/articles/:slug
: URL for individual article pageIf an unauthenticated user visits the above 2 URLs, they should be redirected to
/app/login
page.The issue I'm facing here is, the Private route seems to work only for
/app/articles
(the unauthenticated user gets redirected to/app/login
), but not forapp/articles/:slug
- the page displays the complete article even when the user is unauthenticated.All the pages under both the URLs are prebuilt when I run the gatsby-server so that I can take advantage of static-site performance. I want to just prevent a user from seeing the content if they aren't logged in.
Can you please help me understand if I'm doing something wrong? Here is my code to get the complete picture.
File:
/src/pages/app.js
Individual Article pages is being generated using gatsby
createPages
API insidegatsby-node.js
. And the template resides inside/src/templates/article.js
File:
gatsby-node.js
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions