@auther-sdk/react
v1.4.0
Published
Official React bindings for Auther — drop-in AutherProvider with built-in session management and proactive token refresh.
Maintainers
Readme
@auther-sdk/react
React bindings for Auther: a drop-in AutherProvider with
built-in session management and proactive token refresh, plus a useAuther hook. Wraps
@auther-sdk/frontend.
Install
npm install @auther-sdk/reactUsage
import { AutherProvider, useAuther } from '@auther-sdk/react';
function App() {
return (
// endpoint is optional and defaults to the Auther production API
<AutherProvider clientId="req_live_xxxxxxxxxxxx">
<Dashboard />
</AutherProvider>
);
}
function Dashboard() {
const { user, ready, login, logout } = useAuther();
// `ready` is false until the session is restored from the refresh
// cookie. Gate on it to avoid a logged-out flash on reload.
if (!ready) return <p>Loading...</p>;
if (!user) return <button onClick={login}>Sign in</button>;
return (
<>
<p>Signed in as {user.email}</p>
<button onClick={logout}>Sign out</button>
</>
);
}Full guide at auther.ziloris.com/docs.
License
Apache-2.0, Copyright Ziloris.
