useSlashID()
useSlashID() acts as a wrapper on top of the low level /id SDK. The core SDK is designed to be stateless, while this hook will keep track of authentication state changes.
It can be used like this:
Usage
import { useSlashID } from "@slashid/react"
function Component() {
const { user, logIn, logOut, sid, isLoading, isAuthenticated } = useSlashID()
// ...
}
Whenever logIn and logOut are called the current user value will update making any dependencies render again.
API
| Property | Type | Description |
|---|---|---|
| user | User | undefined | An instance of the User object, available post-login. |
| logIn | (config: LoginConfiguration, options?: LoginOptions) => Promise<User | undefined> | Authenticates the user with respect to your LoginConfiguration. Middleware can be applied here using the second argument LoginOptions. |
| logOut | () => void | Logs the user out and clears the stored user property. |
| sid | SlashID | undefined | A reference to the underlying SlashID object. |
| isLoading | boolean | A flag where true means the SDK is not yet ready. |
| isAuthenticated | boolean | A flag where true means the user has logged in and the user property is available. |