Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@eabdullazyanov/react-native-sms-user-consent
Advanced tools
React Native wrapper for Android's SMS User Consent API, ready to use in React Native apps with minimum effort
React Native wrapper for Android's SMS User Consent API, ready to use in React Native apps with minimum effort.
SMS User Consent API exists only on Android, so this package is Android-only. Calling the APIs on iOS is no-op.
If you want auto-filling on iOS, textContentType="oneTimeCode"
for TextInput
is the way to go. Basically, this is the only way for iOS
yarn add @eabdullazyanov/react-native-sms-user-consent
or
npm install @eabdullazyanov/react-native-sms-user-consent
import React, { useEffect, useState } from 'react';
import { TextInput } from 'react-native';
import { useSmsUserConsent } from '@eabdullazyanov/react-native-sms-user-consent';
const Example = () => {
const [code, setCode] = useState();
const retrievedCode = useSmsUserConsent();
useEffect(() => {
if (retrievedCode) setCode(retrievedCode);
}, [retrievedCode]);
return <TextInput value={code} onChangeText={setCode} />;
};
In the example we use a controlled TextInput
for the code entry. sms
equals to the empty string initially, and whenever an SMS is handled sms
receives its content. We use the useEffect
to update the value when an SMS is handled. Inside the effect we use the retrieveVerificationCode
method to retrieve the code from the SMS and update the input value with it.
useSmsUserConsent(codeLength = 6): string
React hook that starts SMS handling and provides the handled SMS as its return value, which is the empty string initially. Stops handling SMS messages on unmount. Uses startSmsHandling
and retrieveVerificationCode
internally.
This 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.
On iOS it just returns the empty string, so no additional code to handle iOS is needed.
type Event = {
sms?: string;
}
startSmsHandling(onSmsReceived: (event: {sms?: string}) => void): (
stopSmsHandling(): void
)
Starts the native SMS listener that will show the SMS User Consent system prompt. If the user has allowed reading the SMS, then the onSmsReceived
callback is called. onSmsReceived
receives the event object containing the SMS.
Returns stopSmsHandling
function that stops showing the system prompt and stops SMS handling.
retrieveVerificationCode(sms: string, codeLength: number = 6): string | null
Retrieves the verification code from an SMS if there is any.
You can import the whole API as one object if you prefer
import SmsUserConsent from 'react-native-sms-user-consent';
// ...
SmsUserConsent.useSmsUserConsent();
// ...
If 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.
PRs 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.
To make changes, you'll need to follow these steps:
/example
folderyarn
and npx react-native run-android
to build and view the example projectFAQs
React Native wrapper for Android's SMS User Consent API, ready to use in React Native apps with minimum effort
The npm package @eabdullazyanov/react-native-sms-user-consent receives a total of 2,253 weekly downloads. As such, @eabdullazyanov/react-native-sms-user-consent popularity was classified as popular.
We found that @eabdullazyanov/react-native-sms-user-consent demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.