{"id":51043688,"url":"https://github.com/authress/login-react-native","last_synced_at":"2026-06-22T12:02:10.472Z","repository":{"id":348253598,"uuid":"1197146033","full_name":"Authress/login-react-native","owner":"Authress","description":"Authress React Native library that provides managed OAuth2 integration.","archived":false,"fork":false,"pushed_at":"2026-03-31T11:49:48.000Z","size":127,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"release/0.1","last_synced_at":"2026-03-31T13:24:24.199Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Authress.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-31T11:12:25.000Z","updated_at":"2026-03-31T11:49:18.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/Authress/login-react-native","commit_stats":null,"previous_names":["authress/login-react-native"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Authress/login-react-native","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Authress%2Flogin-react-native","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Authress%2Flogin-react-native/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Authress%2Flogin-react-native/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Authress%2Flogin-react-native/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Authress","download_url":"https://codeload.github.com/Authress/login-react-native/tar.gz/refs/heads/release/0.1","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Authress%2Flogin-react-native/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34647750,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-22T02:00:06.391Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-22T12:02:09.037Z","updated_at":"2026-06-22T12:02:10.463Z","avatar_url":"https://github.com/Authress.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://authress.io/static/images/linkedin-banner.png\" alt=\"Authress media banner\"\u003e\n\u003c/p\u003e\n\n# @authress/login-react-native\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://www.npmjs.com/package/@authress/login-react-native\" alt=\"Authress SDK on npm\"\u003e\u003cimg src=\"https://badge.fury.io/js/@authress%2Flogin-react-native.svg\"\u003e\u003c/a\u003e\n    \u003ca href=\"./LICENSE\" alt=\"Apache-2.0\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-Apache%202.0-blue.svg\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://authress.io/community\" alt=\"authress community\"\u003e\u003cimg src=\"https://img.shields.io/badge/Community-Authress-fbaf0b.svg\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nAuthress authentication SDK for React Native. Implements the full OAuth 2.0 login flow with native mobile storage and deep link handling for iOS and Android.\n\n## Installation\n\n```sh\nnpm install @authress/login-react-native react-native-encrypted-storage react-native-nitro-cookies react-native-quick-crypto\n```\n\n## Setup\n\n### Android\n\n**1. Configure the deep link intent filter**\n\nIn `android/app/src/main/AndroidManifest.xml`, add an intent filter to your main activity so Android routes the redirect URI back to your app:\n\n```xml\n\u003cactivity\n  android:name=\".MainActivity\"\n  android:launchMode=\"singleTask\"\n  ...\u003e\n\n  \u003c!-- existing intent filters --\u003e\n\n  \u003cintent-filter\u003e\n    \u003caction android:name=\"android.intent.action.VIEW\" /\u003e\n    \u003c!-- DEFAULT: required for the activity to receive implicit intents from outside the app --\u003e\n    \u003ccategory android:name=\"android.intent.category.DEFAULT\" /\u003e\n    \u003c!-- BROWSABLE: required so Chrome and Chrome Custom Tabs can trigger this intent --\u003e\n    \u003ccategory android:name=\"android.intent.category.BROWSABLE\" /\u003e\n    \u003c!-- Must match the redirectUri you pass to LoginClient --\u003e\n    \u003cdata android:scheme=\"com.yourapp\" android:host=\"auth\" android:pathPrefix=\"/callback\" /\u003e\n  \u003c/intent-filter\u003e\n\u003c/activity\u003e\n```\n\n**2. Forward the deep link to React Native**\n\nIn `android/app/src/main/java/.../MainActivity.kt`, if you aren't already processing intents, you need to accept the callback:\n\n```kotlin\nimport android.content.Intent\nimport com.facebook.react.ReactActivity\n\nclass MainActivity : ReactActivity() {\n  override fun onNewIntent(intent: Intent) {\n    super.onNewIntent(intent)\n    setIntent(intent)\n  }\n}\n```\n\n### iOS\n\n**1. Register the URL scheme**\n\nIn `ios/YourApp/Info.plist`, add:\n\n```xml\n\u003ckey\u003eCFBundleURLTypes\u003c/key\u003e\n\u003carray\u003e\n  \u003cdict\u003e\n    \u003ckey\u003eCFBundleURLSchemes\u003c/key\u003e\n    \u003carray\u003e\n      \u003c!-- Must match the scheme in the redirectUri you pass to LoginClient --\u003e\n      \u003cstring\u003ecom.yourapp\u003c/string\u003e\n    \u003c/array\u003e\n  \u003c/dict\u003e\n\u003c/array\u003e\n```\n\n**2. Forward the deep link to React Native**\n\nIn `ios/YourApp/AppDelegate.swift`:\n\n```swift\nimport React\n\n@UIApplicationMain\nclass AppDelegate: UIResponder, UIApplicationDelegate {\n  func application(_ app: UIApplication, open url: URL,\n                   options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -\u003e Bool {\n    return RCTLinkingManager.application(app, open: url, options: options)\n  }\n}\n```\n\nOr in `AppDelegate.mm` (Objective-C):\n\n```objc\n#import \u003cReact/RCTLinkingManager.h\u003e\n\n- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary\u003cUIApplicationOpenURLOptionsKey,id\u003e *)options {\n  return [RCTLinkingManager application:application openURL:url options:options];\n}\n```\n\n**3. Install native pods**\n\n```sh\ncd ios \u0026\u0026 pod install\n```\n\n## Setup\n\nCreate a single `LoginClient` instance for your app — typically in a module you import wherever authentication is needed.\n\n```ts\nimport { LoginClient } from '@authress/login-react-native';\n\nexport const loginClient = new LoginClient({\n  // Your Authress custom domain — https://authress.io/app/#/setup?focus=domain\n  authressApiUrl: 'https://login.yourdomain.com',\n\n  // Your application ID — https://authress.io/app/#/manage?focus=applications\n  applicationId: 'app_your-app-id',\n\n  // The deep link URI Authress redirects back to after login.\n  // Must match a registered redirect URI for the application.\n  redirectUri: 'com.yourapp://auth/callback',\n});\n```\n\nThe constructor throws synchronously if any required setting is missing or invalid. It also automatically registers a deep link listener — when the user returns from the Authress login page, the SDK completes the authentication request without any extra wiring in your app.\n\n### Optional logger\n\nPass any `console`-compatible logger as the second argument to see debug output:\n\n```ts\nconst loginClient = new LoginClient(settings, console);\n```\n\n---\n\n## Usage\n\nAll methods return a [`Result`](https://github.com/supermacro/neverthrow) from the `neverthrow` library. A `Result` is either `Ok(value)` or `Err(error)` — it never throws. Use `.match()`, `.isOk()`, `.isErr()`, or `.unwrapOr()` to handle both cases.\n\n### Check if the user is logged in\n\nCall this on every route change to keep session state current. It uses a cached token when available; otherwise it calls the Authress server.\n\n```ts\nconst isLoggedIn = await loginClient.userIsLoggedIn();\nif (isLoggedIn) {\n  // session is valid — proceed to the app\n} else {\n  // no active session — show the login screen\n}\n```\n\n### Log in — full authentication flow\n\nStart the login request, open the browser, and the SDK takes care of the rest — it listens for the deep link redirect and completes the authentication automatically.\n\n```ts\nimport { Linking } from 'react-native';\n\nconst result = await loginClient.authenticate({\n  // Optional: specify a connection directly, or let the user pick on the Authress-hosted login page\n  connectionId: 'google',\n});\n\nif (result.isOk()) {\n  // Open the Authress-hosted login page in the device browser\n  await Linking.openURL(result.value.authenticationUrl);\n} else {\n  console.error('Failed to start login', result.error);\n}\n```\n\nWhen the user returns via the deep link, the SDK automatically calls `completeAuthenticationRequest` and resolves any pending `waitForToken` calls.\n\n### Get a token for API calls\n\nUse `waitForToken` when you need a bearer token and are willing to wait for a session to become active (e.g. on app startup while restoring a previous session).\n\n```ts\nconst result = await loginClient.waitForToken({ timeoutInMillis: 5000 });\n\nif (result.isOk()) {\n  // Token is available — retrieve it with getToken()\n  const tokenResult = await loginClient.getToken();\n  if (tokenResult.isOk()) {\n    const token = tokenResult.value;\n    // Use as: Authorization: Bearer \u003ctoken\u003e\n  }\n} else {\n  // result.error.code === 'TokenTimeoutError'\n  // No token arrived within the timeout — redirect to login\n}\n```\n\nUse `getToken()` directly when you need the token string immediately with no waiting:\n\n```ts\nconst tokenResult = await loginClient.getToken();\nif (tokenResult.isOk()) {\n  const token = tokenResult.value;\n}\n// Returns Err(NotLoggedInError) immediately if there is no active session\n```\n\n### Get user identity\n\nReturns decoded claims from the session token — useful for personalising the UI.\n\n```ts\nconst result = await loginClient.getUserIdentity();\n\nif (result.isOk()) {\n  console.log(result.value.userId); // e.g. 'user|00001'\n  // result.value also contains all other JWT claims\n} else {\n  // result.error.code === 'NotLoggedInError'\n}\n```\n\n### Get full user profile\n\nFetches the user's profile from Authress, including all linked identities. Requires an active session.\n\n```ts\nconst result = await loginClient.getUserProfile();\n\nif (result.isOk()) {\n  for (const { connection } of result.value.linkedIdentities) {\n    console.log(connection.connectionId, connection.userId);\n  }\n} else if (result.error.code === 'NotLoggedInError') {\n  // user is not logged in\n} else {\n  // HTTP error\n}\n```\n\n### Log out\n\nClears the local session and invalidates the server-side session.\n\n```ts\nawait loginClient.logout();\n// Result is always Ok — errors during server-side logout are swallowed\n```\n\nAfter logout, `getToken()` returns `Err`, `waitForToken()` blocks again, and `userIsLoggedIn()` returns `false`.\n\n### Link an additional identity\n\nLinks a new identity provider to the currently logged-in user. Follows the same flow as `authenticate` — open `authenticationUrl` in the browser and the SDK handles the redirect automatically. Either `connectionId` or `tenantLookupIdentifier` is required.\n\n```ts\nconst result = await loginClient.linkIdentity({ connectionId: 'github' });\n\nif (result.isOk()) {\n  await Linking.openURL(result.value.authenticationUrl);\n} else if (result.error.code === 'NotLoggedInError') {\n  // user must be logged in to link an identity\n} else {\n  console.error('Link identity failed', result.error);\n}\n```\n\n### MFA devices\n\n```ts\n// List registered MFA devices\nconst devicesResult = await loginClient.getDevices();\nconst devices = devicesResult.unwrapOr([]);\n\n// Remove a device\nconst deleteResult = await loginClient.deleteDevice(deviceId);\nif (deleteResult.isErr()) {\n  console.error('Failed to remove device', deleteResult.error);\n}\n```\n\n---\n\n## Error handling\n\nAll errors are typed and carry a discriminating property. No method throws — use `.isErr()` to check for failure, then inspect the error.\n\n### Application errors\n\nReturned as `Err` values when a precondition is not met. Match on `error.code`:\n\n| Class | `error.code` | When |\n|---|---|---|\n| `NotLoggedInError` | `'NotLoggedInError'` | Operation requires a logged-in session |\n| `NoAuthenticationRequestInProgressError` | `'NoAuthenticationRequestInProgressError'` | `completeAuthenticationRequest` called with no pending login |\n| `AuthenticationRequestMismatchError` | `'AuthenticationRequestMismatchError'` | `authenticationRequestId` in the redirect does not match the pending request |\n| `TokenTimeoutError` | `'TokenTimeoutError'` | `waitForToken` timeout elapsed before a session arrived |\n| `InvalidConnectionError` | `'InvalidConnectionError'` | `linkIdentity` called without `connectionId` or `tenantLookupIdentifier` |\n| `SecurityContextError` | `'SecurityContextError'` | Encrypted storage is unavailable (device security context error) |\n\n### HTTP errors\n\nReturned when a network request to the Authress service fails. All three types are part of the `AuthressHttpError` union. Match on `error.name`:\n\n| `error.name` | When |\n|---|---|\n| `'AuthressHttpNetworkError'` | Request never reached the server (network offline, DNS failure). Retried up to 5 times before returning this error. |\n| `'AuthressHttpClientError'` | Authress returned a 4xx response |\n| `'AuthressHttpServiceError'` | Authress returned a 5xx response |\n\nEach HTTP error includes `url`, `method`, and `data`. Client and service errors also include `status` and `headers`.\n\n### Example: handling all error cases\n\n```ts\nimport type { AuthressHttpError } from '@authress/login-react-native';\n\nconst result = await loginClient.authenticate({ connectionId: 'google' });\n\nif (result.isErr()) {\n  const error = result.error;\n\n  // Application errors — check error.code\n  if (error.code === 'SecurityContextError') {\n    // encrypted storage unavailable — device security context error\n  }\n\n  // HTTP errors — check error.name\n  else if (error.name === 'AuthressHttpNetworkError') {\n    // device is offline\n  } else if (error.name === 'AuthressHttpClientError') {\n    console.error(`Bad request: ${error.status}`, error.data);\n  } else if (error.name === 'AuthressHttpServiceError') {\n    console.error(`Authress service error: ${error.status}`);\n  }\n}\n```\n\n---\n\n## API reference\n\n### `new LoginClient(settings, logger?)`\n\n| Parameter | Type | Required | Description |\n|---|---|---|---|\n| `authressApiUrl` | `string` | Yes | Your Authress custom domain |\n| `applicationId` | `string` | Yes | Your Authress application ID |\n| `redirectUri` | `string` | Yes | Deep link URI registered for the application |\n| `logger` | `Logger` | No | Optional logger (`console` works) |\n\nThrows synchronously on invalid settings.\n\n---\n\n### `userIsLoggedIn()`\n\n`Promise\u003cboolean\u003e`\n\nChecks if a valid session exists. Uses the cached token when available; otherwise calls the Authress API. Returns `Ok(true)` if the session is active, `Ok(false)` if not logged in or if the server call fails.\n\nCall on every route change.\n\n---\n\n### `authenticate(options?)`\n\n`Promise\u003cResult\u003cAuthenticateResponse, AuthressHttpError | SecurityContextError\u003e\u003e`\n\nStarts the login flow. Returns `authenticationUrl` to open in the device browser. The SDK automatically handles the deep link redirect to complete the flow.\n\n| Option | Type | Description |\n|---|---|---|\n| `connectionId` | `string` | Log in directly with a specific provider connection |\n| `tenantLookupIdentifier` | `string` | Resolve the connection from a tenant identifier |\n| `inviteId` | `string` | Accept an invitation |\n| `redirectUrl` | `string` | Override the redirect URI from settings |\n| `scopes` | `string[]` | Additional scopes to request |\n| `audiences` | `string[]` | Additional audiences for the token |\n| `connectionProperties` | `Record\u003cstring, string\u003e` | Provider-specific properties |\n| `multiAccount` | `boolean` | Enable multi-account login (default: `false`) |\n\n---\n\n### `completeAuthenticationRequest(params)`\n\n`Promise\u003cResult\u003cvoid, AuthFlowError | AuthressHttpError\u003e\u003e`\n\nCompletes the login flow after the deep link redirect. Called automatically by the SDK when the deep link is received — you only need to call this directly if you are managing the deep link yourself.\n\n---\n\n### `getToken()`\n\n`Promise\u003cResult\u003cstring, NotLoggedInError\u003e\u003e`\n\nReturns the current bearer token, or `Err(NotLoggedInError)` if there is no active session. Does not wait or make network calls.\n\n---\n\n### `waitForToken(options?)`\n\n`Promise\u003cResult\u003cvoid, TokenTimeoutError\u003e\u003e`\n\nBlocks until a session token is available or the timeout elapses. Use `getToken()` after this resolves to retrieve the token string.\n\n| Option | Type | Default | Description |\n|---|---|---|---|\n| `timeoutInMillis` | `number` | `5000` | Timeout in ms. `0` = fail immediately. `-1` = wait indefinitely. |\n\n---\n\n### `logout()`\n\n`Promise\u003cResult\u003cvoid, never\u003e\u003e`\n\nClears the local session and calls the Authress logout endpoint. Always resolves `Ok` — server-side errors are swallowed.\n\n---\n\n### `getUserIdentity()`\n\n`Promise\u003cResult\u003cUserIdentity, NotLoggedInError\u003e\u003e`\n\nReturns decoded claims from the session token. `identity.userId` is the user's unique identifier. The identity object also contains all other JWT claims.\n\n---\n\n### `getUserProfile()`\n\n`Promise\u003cResult\u003cUserProfile, AuthressHttpError | NotLoggedInError\u003e\u003e`\n\nFetches the user's full profile from Authress, including all linked identities (`profile.linkedIdentities`).\n\n---\n\n### `linkIdentity(options)`\n\n`Promise\u003cResult\u003cAuthenticateResponse, AuthressHttpError | SecurityContextError | NotLoggedInError | InvalidConnectionError\u003e\u003e`\n\nLinks a new identity provider to the current user. Returns `authenticationUrl` to open in the device browser. Either `connectionId` or `tenantLookupIdentifier` is required.\n\n---\n\n### `getDevices()`\n\n`Promise\u003cResult\u003cDevice[], AuthressHttpError | NotLoggedInError\u003e\u003e`\n\nReturns the list of MFA devices registered for the current user. Returns `Ok([])` if not logged in or no devices are registered.\n\n---\n\n### `deleteDevice(deviceId)`\n\n`Promise\u003cResult\u003cvoid, AuthressHttpError | NotLoggedInError\u003e\u003e`\n\nRemoves the MFA device with the given `deviceId`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauthress%2Flogin-react-native","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fauthress%2Flogin-react-native","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauthress%2Flogin-react-native/lists"}