-
Notifications
You must be signed in to change notification settings - Fork 27.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic server usage: Page couldn't be rendered statically because it used cookies
#56630
Comments
Did you try the following? import { createServerComponentClient } from "@supabase/auth-helpers-nextjs";
import { cookies } from "next/headers";
export default () => {
cookies().getAll(); // Keep cookies in the JS execution context for Next.js build
return createServerComponentClient({ cookies });
}; You can then import and use it like this: import supabaseServer from "./supabaseServer";
export const isAuthentificatedServer = async () => {
const {
data: { session },
} = await supabaseServer().auth.getSession();
if (!session) {
return false;
} else {
return true;
}
}; I encountered the same bug and managed to resolve it this way. I'm not exactly sure why this happens, though. I suspect that when Next.js tries to build your app, it somehow loses track of the cookies when executing the function in an asynchronous context. |
You absolutely the best - thank you I improved this code a bit:
import { createServerComponentClient } from "@supabase/auth-helpers-nextjs";
import { cookies } from "next/headers";
import { Database } from "@/interfaces/types_db";
const supabaseServer = () => {
cookies().getAll(); // Keep cookies in the JS execution context for Next.js build
return createServerComponentClient<Database>({ cookies });
};
export default supabaseServer Note: Also I opened new issue - supabase/supabase#18089 Keep building cool stuff :) |
Had the same issue yesterday. Is this a common issue or just a bug from either supabase or nextjs side? |
I'm sure its something from supabase side because not only you have this issue |
There is a very similar example to what @Flushey posted on the Supabase getting started guide that also works, although it uses createRouteHandlerClient instead of createServerComponentClient: |
I want bring attention to this issue because supabase created something that impossible to use Also as I know |
I experienced the same issue locally but when I deployed on Netlify the deployment succeeded |
This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Link to the code that reproduces this issue
codsandbox - https://codesandbox.io/p/github/nicitaacom/auth-cookie-supabase-willbedeleted/auth-form-next
github repository (userIcon.tsx) - https://github.com/nicitaacom/auth-cookie-supabase-willbedeleted/blob/auth-form-next/app/components/Navbar/components/UserIcon.tsx
github repository (userIcon.tsx) - https://github.com/nicitaacom/auth-cookie-supabase-willbedeleted/blob/auth-form-next/app/utils/supabaseServer.ts
To Reproduce
Current vs. Expected behavior
I wait no error but I got the error
Verify canary release
Provide environment information
Which area(s) are affected? (Select all that apply)
Dynamic imports (next/dynamic)
Additional context
Similar issue - #49373
middleware.ts
app/api/auth/callback/route.ts
app/utils/supabaseServer.ts
Update:I updated reproduction link - now you able to open it and have access
The text was updated successfully, but these errors were encountered: