auth-astro icon indicating copy to clipboard operation
auth-astro copied to clipboard

Should support `output=hybrid` + `prerender=false`?

Open Reimirno opened this issue 1 year ago • 1 comments

Of course the page that uses getSession should be SSR. But it seems that output=hybrid with export const prerender=false on the every page that uses auth-astro still leads to the following error (when you login or logout - i.e. when you use auth endpoints):

image

Which I guess I understand why - auth-astro need to inject those auth endpoints but in hybrid mode then are by default SSG which they shouldn't. Putting export const prerender=false on the app pages do not really change anything as they don't affect the endpoint pages - at least that's my understanding.

It is annoying, because the majority of my pages are SSG and only a few pages are SSR and they needs user to login and view. I am doing ok by switching output=server and putting export const prerender=true to all SSG pages (opt in instead of opt out) but I wonder if there is a better workaround / built-in support.

Reimirno avatar Mar 26 '24 23:03 Reimirno

A workaround for this is to set injectEndpoints: false in the auth-astro integration config.

Then, create your own src/pages/api/[...auth].ts with the following:

import { AstroAuth } from "auth-astro/server";

export const prerender = false;

export const { GET, POST } = AstroAuth();

This is the same code that auth-astro injects but with the export const prerender = false; line.

Pseudorizer avatar Apr 23 '24 14:04 Pseudorizer

Hi, thanks for bringing this to my attention. I´ll include

export const prerender = false;

with the next patch, like @MiniCheese26 suggested.

nowaythatworked avatar Jun 12 '24 14:06 nowaythatworked