javascript
@nexauth/sdk
install
npm i @nexauth/sdkFull flow
login.js
import NexAuth from "@nexauth/sdk";
const auth = new NexAuth({
publishableKey: "pk_live_...",
// baseUrl defaults to https://api.nexauth.dev/v1
});
// 1. OTP
const { otpId } = await auth.otp.send({ channel: "whatsapp", to: "+91..." });
const session = await auth.otp.verify({ channel: "whatsapp", to: "+91...", code });
// 2. Google
const session2 = await auth.social.google({ idToken });
// 3. Magic link
await auth.magicLink.send({ email, redirect: "https://app.io/welcome" });
// 4. Passkey
await auth.passkey.register({ userId: session.user.id });
const session3 = await auth.passkey.login({ identifier: "+91..." });
// 5. Session management — auto refresh
auth.onSession((s) => console.log("signed in:", s.user.id));
await auth.signOut(); // revokes refresh tokenError shape
errors
try { await auth.otp.verify(...) }
catch (e) {
e.code // "invalid_code" | "rate_limited" | "expired" | "blocked"
e.retryAfterSec // on rate limits
}