Connect a member
Set up the backend client from the installation guide. In your sign-in POST handler, generate a new authorization request. Save its one-time state and verifier in the visiting member’s server-side session before redirecting tourl.
sessions is your application’s session store. Use an unpredictable cookie with Secure, HttpOnly and SameSite=Lax. Require a same-origin request for the sign-in POST. Your server can redirect straight to url. A client-side button that receives this URL from your server can call the browser helper below.
takePending atomic so two callbacks cannot reuse one request. After success, return the rotated session cookie and redirect to a clean application URL. Keep the verifier, codes and access token out of client code, logs and analytics. If the member declines, return them to your public site. Access tokens expire after ten minutes. Start sign-in again when necessary. To disconnect, call oneswap.auth.revoke(accessToken) and clear your local session.
Protect a route
Register a fixed minimum under My launches → dApps → Holder requirements. For example, set theholder requirement to one available token. Available holdings exclude locked amounts. Total holdings include them. Incoming offers count only after settlement.
This function runs on your server. Call it at the point where you serve private content or perform the protected action. Hiding a button alone leaves the route accessible.
The app receives a decision per approved requirement. It cannot read the user’s balance or supply an arbitrary threshold. A fresh result lasts at most 30 seconds. Read again for each protected action and keep access closed on an exception or expired result. Use
auth.me().capabilities to decide which features to show.
Change a membership tier
An app can register up to eight requirements and twenty experiences for its own token. In Holder requirements or Experiences, select Edit. Their IDs stay the same. Changing a requirement creates a new revision. When the server returnsRULE_NOT_CONSENTED, invite the member to reconnect and review the updated requirement. Other requirements retain their existing consent.
A 401 on a member token can require a new sign-in. If the SDK reports INVALID_CLIENT, check your server key and website verification. On a 429, wait for retryAfterMs when available and back off before retrying. Never turn an error into a successful holder check.