7dfbbf6124
- Deleted various texture files related to the Raspberry Pi camera model. - Introduced a new JSON file to store model metadata including IDs, names, and URLs. - Implemented authentication and session management using Supabase. - Created a header component for navigation and user session display. - Added protected routes to restrict access to certain pages. - Developed a private layout for authenticated users. - Enhanced the home page to dynamically load models from the new JSON file. - Updated the login page to handle user authentication. - Created a model uploader for users to upload 3D models. - Improved overall styling and layout for better user experience.
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
import { createContext, useContext, useEffect, useState } from "react";
|
|
import { supabase } from "./supabase";
|
|
import { Session } from "@supabase/supabase-js";
|
|
|
|
type AuthContextType = {
|
|
session: Session | null;
|
|
loading: boolean;
|
|
};
|
|
|
|
const AuthContext = createContext<AuthContextType>({ session: null, loading: true });
|
|
|
|
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
|
const [session, setSession] = useState<Session | null>(null);
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
useEffect(() => {
|
|
supabase.auth.getSession().then(({ data: { session } }) => {
|
|
setSession(session);
|
|
setLoading(false);
|
|
});
|
|
|
|
const { data: listener } = supabase.auth.onAuthStateChange((_event, session) => {
|
|
setSession(session);
|
|
});
|
|
|
|
return () => {
|
|
listener.subscription.unsubscribe();
|
|
};
|
|
}, []);
|
|
|
|
return (
|
|
<AuthContext.Provider value={{ session, loading }}>
|
|
{children}
|
|
</AuthContext.Provider>
|
|
);
|
|
}
|
|
|
|
export function useAuth() {
|
|
return useContext(AuthContext);
|
|
}
|