Create the SDK client
Use the app ID and redirect URL from your ONE app.
import { ONE } from "@one/sdk";
const one = new ONE({
appId: "one_test_123",
redirectUri: `${window.location.origin}/auth/one`,
});
npm install @one/sdk
Use the app ID and redirect URL from your ONE app.
import { ONE } from "@one/sdk";
const one = new ONE({
appId: "one_test_123",
redirectUri: `${window.location.origin}/auth/one`,
});
Ask only for what your app needs.
await one.login({
age: "18+",
email: "optional",
});
Send the signed proof to your server.
const proof = await one.completeLogin();
await fetch("/api/session", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ proof }),
});
appId
required
Your public ONE app ID.
redirectUri
required
Where ONE returns the user. Add the exact URL to your ONE app.
Email is not shared by default.
email: false
Do not ask. This is the default.
email: "optional"
The user may share it. Login continues if they decline.
email: "required"
The user must share it to continue.
await one.login({
age: "18+",
email: "required",
});
The verified server result has one stable shape.
type Login = {
user: {
id: string;
email?: string;
};
age?: {
over18: true;
verifiedAt: string;
};
};
try {
const proof = await one.completeLogin();
} catch (error) {
if (error.code === "access_denied") {
// The user stopped login.
}
}
Show a retry. Do not treat an incomplete check as a failed age check.
new ONE(options)
Creates a browser client.
one.login(request)
Redirects the user to ONE.
one.completeLogin()
Checks the callback and returns a signed proof.
Send the proof to your backend. Verify it before creating a session.
@one/node
Coming later
one
Coming later
one-go
Coming later
Server SDKs will verify the signature, issuer, audience, expiry, and age credential. The proof format is open for other languages.