fix: syntax error in AuthContext
This commit is contained in:
parent
b96fb0d0e4
commit
31348cb6d1
1 changed files with 42 additions and 39 deletions
|
|
@ -177,46 +177,49 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
const deleteTicket = useCallback(async (ticketId: number) => {
|
|
||||||
if (!authHeader) return
|
|
||||||
try {
|
|
||||||
const res = await fetch(`${API_URL}/tickets/${ticketId}`, {
|
|
||||||
method: "DELETE",
|
|
||||||
headers: { "Authorization": authHeader }
|
|
||||||
})
|
|
||||||
if (res.ok) {
|
|
||||||
fetchTickets(authHeader)
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e)
|
|
||||||
}
|
|
||||||
}, [authHeader, fetchTickets])
|
|
||||||
|
|
||||||
return (
|
|
||||||
<AuthContext.Provider
|
|
||||||
value={{
|
|
||||||
user,
|
|
||||||
tickets,
|
|
||||||
rooms,
|
|
||||||
authHeader,
|
|
||||||
login,
|
|
||||||
register,
|
|
||||||
logout,
|
|
||||||
createTicket,
|
|
||||||
updateTicketStatus,
|
|
||||||
deleteTicket,
|
|
||||||
updateRooms,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</AuthContext.Provider>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
}, [authHeader, fetchTickets])
|
||||||
|
|
||||||
export function useAuth() {
|
const deleteTicket = useCallback(async (ticketId: number) => {
|
||||||
const context = useContext(AuthContext)
|
if (!authHeader) return
|
||||||
if (!context) {
|
try {
|
||||||
throw new Error("useAuth must be used within an AuthProvider")
|
const res = await fetch(`${API_URL}/tickets/${ticketId}`, {
|
||||||
|
method: "DELETE",
|
||||||
|
headers: { "Authorization": authHeader }
|
||||||
|
})
|
||||||
|
if (res.ok) {
|
||||||
|
fetchTickets(authHeader)
|
||||||
}
|
}
|
||||||
return context
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
}
|
}
|
||||||
|
}, [authHeader, fetchTickets])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AuthContext.Provider
|
||||||
|
value={{
|
||||||
|
user,
|
||||||
|
tickets,
|
||||||
|
rooms,
|
||||||
|
authHeader,
|
||||||
|
login,
|
||||||
|
register,
|
||||||
|
logout,
|
||||||
|
createTicket,
|
||||||
|
updateTicketStatus,
|
||||||
|
deleteTicket,
|
||||||
|
updateRooms,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</AuthContext.Provider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useAuth() {
|
||||||
|
const context = useContext(AuthContext)
|
||||||
|
if (!context) {
|
||||||
|
throw new Error("useAuth must be used within an AuthProvider")
|
||||||
|
}
|
||||||
|
return context
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue