Skip to content

francopicc/auth-context

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Auth Context for Supabase

Supabase Logo

A simple and reusable React context for managing authentication with Supabase. This package provides an easy way to manage the user's session and authentication state in your React app.

Features

  • Provides a React context (AuthContext) to manage the Supabase session and user.
  • Custom hook useAuth() to access session and user data easily.
  • Supports dynamic Supabase URL and anon key configuration.
  • Works seamlessly with React functional components.

Installation

To install the package, run:

npm install auth-context-supabase

or

yarn add auth-context-supabase

Usage

Wrap your application with the AuthProvider and pass your Supabase URL and anon key.

import { AuthProvider } from "auth-context-supabase";

function App() {
  return (
    <AuthProvider supabaseUrl="YOUR_SUPABASE_URL" supabaseAnonKey="YOUR_SUPABASE_ANON_KEY">
      <YourApp />
    </AuthProvider>
  );
}

Use the useAuth hook to access the session, user, and loading state in any component.

import { useAuth } from "auth-context-supabase";

function UserProfile() {
  const { session, user, loading } = useAuth();

  if (loading) return <div>Loading...</div>;

  if (!session) return <div>Please log in</div>;

  return (
    <div>
      <h1>Hello, {user?.email}</h1>
    </div>
  );
}

Contributing

If you'd like to contribute, please fork the repository and submit a pull request. For major changes, please open an issue first to discuss what you would like to change.

About

Context and Hooks for Supabase Auth.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors