{"id":26214567,"url":"https://github.com/akvelon/react-native-sms-user-consent","last_synced_at":"2025-04-06T07:10:11.755Z","repository":{"id":37822113,"uuid":"330623632","full_name":"akvelon/react-native-sms-user-consent","owner":"akvelon","description":"React Native wrapper for Android's SMS User Consent API, ready to use in React Native apps with minimum effort.","archived":false,"fork":false,"pushed_at":"2024-04-26T07:30:55.000Z","size":591,"stargazers_count":85,"open_issues_count":2,"forks_count":38,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-04-26T11:44:22.448Z","etag":null,"topics":["2fa","android","auth","authentication","code","mobile","one-time","otp","react-native","two-factor","verification"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akvelon.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2021-01-18T09:58:40.000Z","updated_at":"2024-06-18T22:53:20.451Z","dependencies_parsed_at":"2024-01-15T10:03:28.286Z","dependency_job_id":"1a3f29df-ebe1-4f84-a160-1a7c7a98ea88","html_url":"https://github.com/akvelon/react-native-sms-user-consent","commit_stats":{"total_commits":83,"total_committers":6,"mean_commits":"13.833333333333334","dds":"0.40963855421686746","last_synced_commit":"dd7e7e6698aab78c0437c77aca86d5ece19ff65d"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akvelon%2Freact-native-sms-user-consent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akvelon%2Freact-native-sms-user-consent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akvelon%2Freact-native-sms-user-consent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akvelon%2Freact-native-sms-user-consent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akvelon","download_url":"https://codeload.github.com/akvelon/react-native-sms-user-consent/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247445668,"owners_count":20939958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["2fa","android","auth","authentication","code","mobile","one-time","otp","react-native","two-factor","verification"],"created_at":"2025-03-12T10:17:47.338Z","updated_at":"2025-04-06T07:10:11.729Z","avatar_url":"https://github.com/akvelon.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React Native SMS User Consent\n\nReact Native wrapper for Android's SMS User Consent API, ready to use in React Native apps with minimum effort. The purpose of SMS User Consent API is to provide one-tap auto-filling of SMS verification codes.\n\n## iOS\n\nSMS User Consent API exists only on Android, so this package is Android-only. Calling this package's APIs on iOS is no-op.\n\nIf you want auto-filling on iOS, `textContentType=\"oneTimeCode\"` for `TextInput` is the way to go. Basically, this is the only way for iOS.\n\n## Getting started\n\nInstall [the package](https://www.npmjs.com/package/@eabdullazyanov/react-native-sms-user-consent):\n\n```\nyarn add @eabdullazyanov/react-native-sms-user-consent\n```\n\nor\n\n```\nnpm install @eabdullazyanov/react-native-sms-user-consent\n```\n\n## Basic usage\n\n```javascript\nimport React, { useEffect, useState } from 'react';\nimport { TextInput } from 'react-native';\n\nimport { useSmsUserConsent } from '@eabdullazyanov/react-native-sms-user-consent';\n\nconst Example = () =\u003e {\n  const [code, setCode] = useState();\n\n  const retrievedCode = useSmsUserConsent();\n\n  useEffect(() =\u003e {\n    if (retrievedCode) setCode(retrievedCode);\n  }, [retrievedCode]);\n\n  return \u003cTextInput value={code} onChangeText={setCode} /\u003e;\n};\n```\n\nIn the example we use a controlled `TextInput` for the code entry. `retrievedCode` equals to the empty string initially, and whenever an SMS is handled `retrievedCode` receives the code from it. We use the `useEffect` to update the input value when an SMS is handled.\n\n### Customise verification code parser\n\nSet the length of the validation code:\n\n```typescript\nconst retrievedCode = useSmsUserConsent(4);\n// e.g. code = 1234\n```\n\nProvide a custom regular expression:\n\n```typescript\nconst retrievedCode = useSmsUserConsent('[A-Z0-9]{5}');\n// e.g. code = A12B3\n```\n\n## API\n\n### useSmsUserConsent()\n\n```typescript\nuseSmsUserConsent(config: number | string): string\n```\n\nReact hook that starts SMS handling and provides the received code as its return value, which is the empty string initially. Stops handling SMS messages on unmount. Uses `startSmsHandling` and `retrieveVerificationCode` internally.\n\nThis hook is the way to go in most cases. Alternatively, you can use `startSmsHandling` and `retrieveVerificationCode` directly if dealing with something that is not a functional component or you need some more flexibility.\n\nOn iOS it just returns the empty string, so no additional code to handle iOS is needed.\n\nAccepts an optional `config` parameter. In case if it's a number, it defines the length of the code. In case if it is a string, it defines a custom RegExp to parse the code.\n\n### startSmsHandling()\n\n```typescript\nstartSmsHandling(onSmsReceived: (event: {sms?: string}) =\u003e void): (\n  stopSmsHandling(): void\n)\n```\n\nStarts the native SMS listener that will show the SMS User Consent system prompt. If the user allowed reading the SMS, then the `onSmsReceived` callback is called. `onSmsReceived` receives the event object containing the SMS.\n\nReturns `stopSmsHandling` function that stops showing the system prompt and stops SMS handling.\n\n### retrieveVerificationCode()\n\n```typescript\nretrieveVerificationCode(sms: string, config: number | string): string | null\n```\n\nRetrieves the verification code from an SMS if there is any.\n\nAccepts an optional `config` parameter. In case if it's a number, it defines the length of the code. In case if it is a string, it defines a custom RegExp to parse the code.\n\n---\n\n*You can import the whole API as one object if you prefer*\n\n```javascript\nimport SmsUserConsent from 'react-native-sms-user-consent';\n\n// ...\nSmsUserConsent.useSmsUserConsent();\n// ...\n```\n\n## Help\n\nIf you have any ideas about the project or found a bug or have a question, feel free to create an issue with all the relevant information. We are engaged to response ASAP. The following info will make it faster to resolve issues:\n\n1. Device or emulator model\n2. Android version\n3. Your environment info - output of the `npx react-native info` command\n\n## Contribution\n\nPRs are always welcome. If you're feeling like contributing to the project, please do. It would be great to have all the relevant information with the PR.\n\nTo make changes, you'll need to follow these steps:\n\n1. clone the repo\n2. make changes\n3. test the changes\n4. create a PR\n5. 🥳\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakvelon%2Freact-native-sms-user-consent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakvelon%2Freact-native-sms-user-consent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakvelon%2Freact-native-sms-user-consent/lists"}