0.3.1 UI修复
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import type { Session } from "@supabase/supabase-js";
|
||||
import { SessionContextProvider } from "@supabase/auth-helpers-react";
|
||||
import { getSupabaseBrowserClient } from "@/lib/supabase/client";
|
||||
|
||||
interface SupabaseProviderProps {
|
||||
session: Session | null;
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export function SupabaseProvider({ session, children }: SupabaseProviderProps) {
|
||||
useEffect(() => {
|
||||
const supabaseBrowser = getSupabaseBrowserClient();
|
||||
const {
|
||||
data: { subscription },
|
||||
} = supabaseBrowser.auth.onAuthStateChange((_event, newSession) => {
|
||||
fetch("/api/auth/callback", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
credentials: "include",
|
||||
body: JSON.stringify({ event: _event, session: newSession }),
|
||||
});
|
||||
});
|
||||
|
||||
supabaseBrowser.auth.getSession().then(({ data }) => {
|
||||
if (data.session) {
|
||||
fetch("/api/auth/callback", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
credentials: "include",
|
||||
body: JSON.stringify({ event: "INITIAL_SESSION", session: data.session }),
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
subscription.unsubscribe();
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<SessionContextProvider
|
||||
supabaseClient={getSupabaseBrowserClient()}
|
||||
initialSession={session}
|
||||
>
|
||||
{children}
|
||||
</SessionContextProvider>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user