NextJS App Directory SSR issue.
a

a_tree.

over 1 year ago
Hello, I have been having trouble with getting Next.JS App Directory SSR to work properly. I've been following the documentation on https://supertokens.com/docs/thirdparty/nextjs/app-directory/protecting-route#sessions-with-server-components--pre and looked at the repository (https://github.com/supertokens/next.js/tree/canary/examples/with-supertokens/app). (I last checked these pages and followed them today, 2/9/2024) The components sessionAuthForNextJS.tsx and tryRefreshClientComponent.tsx are the same and I followed the code stated in home.tsx. Looking at my configuration files, they seem to be correct. When I attempt to log in, it works just fine and such. Then if I try to go to my dashboard, which has the SSR authentication requirement, I will first be redirected to the auth page for a moment then pushed to the home page '/'. Then every other attempt of trying to go to the dashboard will just continue to redirect me to the home page '/'. If convert the SSR pages into their client side version then it works just fine, however I want to use SSR for increased performance and user experience. I then got confused with the middleware, thinking it was part of the SSR before realizing it was only for APIs, but the middleware approach did fix my issues, until expiration occurred and I'd get a "Authentication required" message. As a temporary fix to this, the user would need to go back to the home page and then they'd be able to go to the dashboard and its sub pages. This sort of works but there are pages where users would go straight to a sub page within the dashboard, so they'd get this message often. Figuring out that the middleware was only for APIs, I went back and commented it out. I am now at square one with SSR authentication again and can't seem to figure out why I am only redirected to the home page and never allowed into my dashboard.