Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

772 B
Raw Blame
/**
 * The single React context backing `useAuth()`. Both the Spring and Supabase
 * providers write to this same context so consumers read a unified value
 * regardless of which backend authenticated the user.
 */
import { createContext, useContext } from "react";
import type { AuthContextValue } from "@editor/auth/types";

export const AuthContext = createContext<AuthContextValue>({
  session: null,
  user: null,
  displayName: null,
  isAnonymous: false,
  isAdmin: false,
  portalAccess: false,
  role: null,
  loading: true,
  error: null,
  signOut: async () => {},
  refreshSession: async () => {},
});

/** Access the current auth state. Must be used within an AuthProvider. */
export function useAuth(): AuthContextValue {
  return useContext(AuthContext);
}