# useAuth

> **useAuth**(): [`AuthState`](https://ic-reactor.b3pay.net/v4/libs/interfaces/authstate/) & `object`

Defined in: [react/src/index.tsx:585](https://github.com/B3Pay/ic-reactor/blob/6b3b9f58b7868082175216ca6e3688d278d17c1f/packages/react/src/index.tsx#L585)

Who calls, and how to change it: the client's [AuthState](https://ic-reactor.b3pay.net/v4/libs/interfaces/authstate/) (`status`
and `principal`) with `signIn` and `signOut` forwarded to the client.

It follows the client with `useSyncExternalStore`, so a component renders
again once per change of status or principal and never otherwise (a renewed
delegation, or a parent that renders, does not). The object it returns is
the same until the state changes, so it is safe in a dependency array or
as a prop of a memoized child.

On a server, and while a page hydrates, the state is `anonymous`: the
server has no session, and rendering the browser's would not match the
server's HTML. A browser whose state is another one (signed in, or a session
that expired or is signed in elsewhere) renders the component again with its
own state right after hydration; an anonymous one does not, and keeps the
object. A component that reads `status` before then should show the same
thing signed out and while the session is read. Whenever it moves on after
hydrating (a signed-in reload, or a session that expired or is signed in
elsewhere), it renders a Suspense boundary still dehydrated below it on the
client, as for [useClient](https://ic-reactor.b3pay.net/v4/libs/functions/useclient/).

`signIn` and `signOut` reject like [Client.signIn](https://ic-reactor.b3pay.net/v4/libs/interfaces/client/#signin) and
[Client.signOut](https://ic-reactor.b3pay.net/v4/libs/interfaces/client/#signout): on a client built with `identity`, which has no
sign-in, and on a server.

## Returns

## Throws

Error outside a [ReactorProvider](https://ic-reactor.b3pay.net/v4/libs/functions/reactorprovider/).