Files
spotizerr-dev/spotizerr-ui/src/contexts/auth-context.ts
2025-08-03 20:16:07 -06:00

17 lines
502 B
TypeScript

import { createContext, useContext } from "react";
import type { AuthContextType } from "@/types/auth";
export const AuthContext = createContext<AuthContextType | null>(null);
export function useAuth() {
const context = useContext(AuthContext);
if (!context) {
throw new Error("useAuth must be used within an AuthProvider");
}
return context;
}
// Optional hook that doesn't throw an error if used outside provider
export function useAuthOptional() {
return useContext(AuthContext);
}