31 lines
872 B
TypeScript
31 lines
872 B
TypeScript
"use client"
|
|
|
|
import type React from "react"
|
|
|
|
import { createContext, useContext } from "react"
|
|
import { useAuth, type User } from "@/lib/hooks/use-auth"
|
|
|
|
interface AuthContextType {
|
|
user: User | null
|
|
login: (email: string, password: string) => Promise<boolean>
|
|
register: (userData: Omit<User, "id" | "createdAt"> & { password: string }) => Promise<boolean>
|
|
logout: () => void
|
|
isLoading: boolean
|
|
}
|
|
|
|
const AuthContext = createContext<AuthContextType | undefined>(undefined)
|
|
|
|
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
|
const auth = useAuth()
|
|
|
|
return <AuthContext.Provider value={auth}>{children}</AuthContext.Provider>
|
|
}
|
|
|
|
export function useAuthContext() {
|
|
const context = useContext(AuthContext)
|
|
if (context === undefined) {
|
|
throw new Error("useAuthContext must be used within an AuthProvider")
|
|
}
|
|
return context
|
|
}
|