@authyo/auth-react
v1.0.0
Published
React wrapper for the Authyo passwordless SDK.
Maintainers
Readme
@authyo/auth-react
React wrapper for the Authyo passwordless SDK. Depends on @authyo/auth-js and exposes a simple context/provider plus a useAuthyo hook.
Install
npm install @authyo/auth-js @authyo/auth-react
# or
yarn add @authyo/auth-js @authyo/auth-reactPeer dependencies: react (^17|^18|^19).
Setup
import React from "react";
import { AuthyoProvider } from "@authyo/auth-react";
function App() {
return (
<AuthyoProvider
clientId="YOUR_CLIENT_ID"
clientSecret="YOUR_CLIENT_SECRET"
baseUrl="https://app.authyo.io" // optional, defaults to this
>
<YourApp />
</AuthyoProvider>
);
}You can also pass an existing AuthyoClient via client prop if you manage it yourself.
Use in components
import { useAuthyo } from "@authyo/auth-react";
function SendOtpButton() {
const authyo = useAuthyo();
const handleClick = async () => {
await authyo.sendOtp({ to: "[email protected]", authWay: "Email", otpLength: 6 });
};
return <button onClick={handleClick}>Send OTP</button>;
}API (via useAuthyo -> AuthyoClient)
getConfiguration()sendOtp({ to, authWay, otpLength, expiry, deviceInfo })verifyOtp(otp, maskId)verifyToken(token)revokeSession(token)
All requests include clientId / clientSecret in headers (configured in the provider or prebuilt client).
Notes
- Context-based; ensure components using
useAuthyoare wrapped byAuthyoProvider. - Keep
clientSecretserver-side where possible; avoid shipping secrets into public bundles you don't control.
Build
npm run buildemits ESM + d.ts todist/
License
MIT
