Skip to content

Commit

Permalink
fix(with-nextjs-supabase): dynamic api was called outside request
Browse files Browse the repository at this point in the history
  • Loading branch information
alicanerdurmaz committed May 27, 2024
1 parent dfffc9e commit a3cd6af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { AuthProvider } from "@refinedev/core";
import { supabaseServerClient } from "@utils/supabase/server";
import { createSupabaseServerClient } from "@utils/supabase/server";

export const authProviderServer: Pick<AuthProvider, "check"> = {
check: async () => {
const { data, error } = await supabaseServerClient.auth.getSession();
const { data, error } =
await createSupabaseServerClient().auth.getSession();
const { session } = data;

if (error) {
Expand Down
18 changes: 9 additions & 9 deletions examples/with-nextjs-supabase/src/utils/supabase/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import { createServerClient, type CookieOptions } from "@supabase/ssr";
import { cookies } from "next/headers";
import { SUPABASE_KEY, SUPABASE_URL } from "./contants";

export const supabaseServerClient = createServerClient(
SUPABASE_URL,
SUPABASE_KEY,
{
export const createSupabaseServerClient = () => {
const cookieStore = cookies();

return createServerClient(SUPABASE_URL, SUPABASE_KEY, {
cookies: {
get(name: string) {
return cookies().get(name)?.value;
return cookieStore.get(name)?.value;
},
set(name: string, value: string, options: CookieOptions) {
try {
cookies().set({ name, value, ...options });
cookieStore.set({ name, value, ...options });
} catch (error) {
// The `set` method was called from a Server Component.
// This can be ignored if you have middleware refreshing
Expand All @@ -21,13 +21,13 @@ export const supabaseServerClient = createServerClient(
},
remove(name: string, options: CookieOptions) {
try {
cookies().set({ name, value: "", ...options });
cookieStore.set({ name, value: "", ...options });
} catch (error) {
// The `delete` method was called from a Server Component.
// This can be ignored if you have middleware refreshing
// user sessions.
}
},
},
},
);
});
};

0 comments on commit a3cd6af

Please sign in to comment.