#Yea thats what Im doing too

1 messages · Page 1 of 1 (latest)

willow epoch
astral flameBOT
#

Hi @willow epoch. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

willow epoch
#

but I have a similar situation where I just want to render in some stuff if they are logged in, or some stuff hidden if they arent...

so what I had to do to acomplish this while keep static for performance is the following:

have two pages
/example/[slug]
and /example/[slug]/auth

They both share a component which is basically the entire page which takes in a session object.

In my middleware I rewrite the page if they are logged in or not.

SO if they are logged in I rewrite to example/[slug]/auth and pass the session via the getServerSession

and if they arent logged in I just do NextResponse.next().

the auth page will be SSR sadly, but atleast not logged in users will have that static page. This was like the best I could get out of both worlds..

but if you wanted even logged in users to keep static performance benifits shit out of luck tbj

astral flameBOT
#

Sorry @willow epoch, I seem to be having a bit of trouble. Don't worry though, I've pinged my supprt and they will try to fix me up! :technologist:

Perhaps try again in 15mins?

winged temple
#

Ah interesting - I'm currently doing something similar using pages with middleware. In the middleware I check the route if it contains the route that needs to be protected, then get the session:

if (pathname.startsWith("/tuesday-makers")){

const location = pathname.split("/")[2];
const session = await getToken({
        req,
        secret: process.env.NEXTAUTH_SECRET,
      });

location variable looks to see if they are trying to visit tuesday-makers/members which is the same as example/[slug]/auth in your scenario.

Then I check if they are trying to visit that members route and if the session is present I let them through

willow epoch
#

Well the difference is

#

Is that my two routes I mentioned share the same server component

#

That renders the entire page

#

Each route calls it

#

The non auth route passes a null session meanwhile the auth route uses the getserverwide function and passes that

#

So I basically have a shared component rendered on two separate pages based on the session parameter given to it

winged temple
#

Ah ok thats cool

winged temple
willow epoch
#

I do not

winged temple
#

Just curious, new issue I've encountered since upgrading