Skip to main content

useAuth

Hook with no arguments that returns two authentication functions used internally by React Bricks to execute the login and logout.

When using React Bricks admin components, there should be no need to call this from your code.

Example usage

const { loginUser, logoutUser } = useAuth()

loginUser

Function with the following signature:

const loginUser: (email: string, password: string) => Promise<any>

Example usage

const { loginUser } = useAuth()

const handleLogin = (event: React.FormEvent) => {
event.preventDefault()
loginUser(email, password).then(
() => navigate(editorPath),
(error) => {
setError(error)
}
)
}

logoutUser

Function with the following signature:

const logoutUser: () => void

Example usage

const { logoutUser } = useAuth()
return <button onClick={() => logoutUser()}>Logout</button>