Skip to main content
Use @offline-protocol/id-react@0.3.0 for hosted email sign-in, profiles and connections. Create an application and add the origins your site runs on, with the CLI (or the developer portal’s Domains tab):
The appId prop is the application’s public identifier, not a secret key. A sign-in from an origin that is not on the list is refused with origin_not_allowed; see allowed web origins.

Add the provider and sign-in control

Supply the App ID from your environment configuration. In Next.js, keep this provider and the components using its hooks in a client component. A public App ID can be present in browser code; administrative API credentials cannot. loginWithModal() opens the email authentication UI and returns void. Read user and loading to observe the result. Sign-in requires network access to the hosted service. See OfflineID hooks for profile and connection APIs, or Mesh SDK identity for local device authentication.

Application attribution

For Next.js, use a public configuration value such as NEXT_PUBLIC_OFFLINE_APP_ID=app_your_application_id. Pass that value as appId. Versions 0.2.0 and later send the App ID in x-app-id, and still send the legacy x-project-id header with the same value. Sign-ins are attributed to the application for analytics, app membership and billing pauses. Direct HTTP integrations send X-App-Id explicitly.

Upgrade from 0.2.x

  • sendCode resolves to true, and throws an OfflineIdError when the server refuses the request or does not answer. In 0.2.x it resolved to false and the reason was lost. Catch the error where you tested the result:
  • verifyCode still resolves to null for a wrong or expired code, and throws an OfflineIdError for any other failure (a plain Error in 0.2.0). Its message is the server’s.
  • An OfflineIdError carries code (such as origin_not_allowed, invalid_app or code_requests_limited; network_error when no response arrived), status, message, missing, nextSteps, docs, appId and reason. For origin_not_allowed, nextSteps starts with offline apps origins add <this page's origin>.

Upgrade from 0.1.x

  • Pass appId to OfflineAppProvider and call setAppId. projectId and setProjectId still work but are deprecated.
  • verifyCode resolves to null when the code is wrong or expired, and throws for any other failure: a network error, a timeout, an invalid email, an origin the application does not allow, a server error or a rate limit. In 0.1.x it threw in both cases.
  • useLocation is removed. Use @offline-protocol/pol for Proof of Location.
  • addConnection resolves to a connection in the same shape as each item in connections, and useConnections() adds setLocationSharing. See OfflineID hooks.
  • Requests time out after 15 seconds and fail like a network error. A write that timed out may still have reached the server, so retrying it can repeat it.
  • The package is licensed under MIT (0.1.5 was published as ISC).