Links

useCorbadoSession()

State
Type
Description
shortSession
string | undefined
A JWT that proves that the user is authenticated. It can be used to make calls to your backend and thus should be included as an Authorization Header in the requests to such a backend. A value of undefined indicates that the user is not logged in.
user
SessionUser | undefined
On object that holds basic information about the user. A value of undefined indicates that the user is not logged in.
loading
boolean
If true, the SDK is still in a loading state. You should then not yet make use of the other states but wait until loading = false.
This is a very simple example that shows how you can use this hook to render a page that depends on the user's authentication state.
import { useCorbado } from "@corbado/react"
function HomePage() {
const { loading, user } = useCorbadoSession()
if (loading) {
return <p>Loading...</p>
}
return (
<>
<p>Hi, {user?.name}. You are logged in!</p>
<button onClick={logout}>Logout</button>
</>
)
}