mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-18 11:51:41 +03:00
9bb7ccf651
* feat: add providers mocks * test(<ChatPage/>: add render test using providers
44 lines
958 B
TypeScript
44 lines
958 B
TypeScript
"use client";
|
|
|
|
import {
|
|
createBrowserSupabaseClient,
|
|
Session,
|
|
} from "@supabase/auth-helpers-nextjs";
|
|
import { useRouter } from "next/navigation";
|
|
import { createContext, useEffect, useState } from "react";
|
|
|
|
import { SupabaseContextType } from "./types";
|
|
|
|
export const SupabaseContext = createContext<SupabaseContextType | undefined>(
|
|
undefined
|
|
);
|
|
|
|
export const SupabaseProvider = ({
|
|
children,
|
|
session,
|
|
}: {
|
|
children: React.ReactNode;
|
|
session: Session | null;
|
|
}): JSX.Element => {
|
|
const [supabase] = useState(() => createBrowserSupabaseClient());
|
|
const router = useRouter();
|
|
|
|
useEffect(() => {
|
|
const {
|
|
data: { subscription },
|
|
} = supabase.auth.onAuthStateChange(() => {
|
|
router.refresh();
|
|
});
|
|
|
|
return () => {
|
|
subscription.unsubscribe();
|
|
};
|
|
}, [router, supabase]);
|
|
|
|
return (
|
|
<SupabaseContext.Provider value={{ supabase, session }}>
|
|
<>{children}</>
|
|
</SupabaseContext.Provider>
|
|
);
|
|
};
|