Context and Hooks for Supabase Auth.
npm install auth-context-supabaseAuthContext) to manage the Supabase session and user.
useAuth() to access session and user data easily.
bash
npm install auth-context-supabase
`
or
`bash
yarn add auth-context-supabase
`
Usage
Wrap your application with the AuthProvider and pass your Supabase URL and anon key.
`tsx
import { AuthProvider } from "auth-context-supabase";
function App() {
return (
);
}
`
Use the `useAuth` hook to access the session, user, and loading state in any component.
`tsx
import { useAuth } from "auth-context-supabase";
function UserProfile() {
const { session, user, loading } = useAuth();
if (loading) return Loading...;
if (!session) return Please log in;
return (
Hello, {user?.email}
);
}
``