Initial commit
This commit is contained in:
30
components/auth-provider.tsx
Normal file
30
components/auth-provider.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
"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
|
||||
}
|
Reference in New Issue
Block a user