react-native-secure-network
v0.2.3
Published
react-native-secure-network is a simple and reliable React Native library designed to assess the security of the device’s active network connection. It identifies whether the network is Wi-Fi or mobile data, checks if the Wi-Fi network is open or protecte
Maintainers
Readme
react-native-secure-network
react-native-secure-network is a simple and reliable React Native library designed to assess the security of the device's active network connection. It identifies whether the network is Wi-Fi or mobile data, checks if the Wi-Fi network is open or protected, and inspects the encryption type (such as WPA/WPA2). This allows developers to block or warn users when their device is connected to an insecure network.
📦 Installation
NPM:
npm install react-native-secure-networkYarn:
yarn add react-native-secure-network🚀 Usage
Import the react-native-secure-network library:
import Network from 'react-native-secure-network';Note: This library provides only promise-based functions.
Using Promises
Network.getConnectionStatus()
.then((response) => {
// Handle success
console.log(response);
})
.catch((error) => {
// Handle error
console.error(error);
});Using Async/Await
async function checkNetwork() {
try {
const response = await Network.getConnectionStatus();
// Handle success
console.log(response);
} catch (error) {
// Handle errors
console.error(error);
}
}📚 API Reference
Available Methods
| Method | Return Type | iOS | Android |
| ----------------------- | ----------- | :-: | :-----: |
| getConnectionStatus() | Promise | ✅ | ✅ |
getConnectionStatus()
Checks the security status of the device's current network connection.
Usage:
const response = await Network.getConnectionStatus();Response Object:
{
isSecureNetwork: boolean;
message: string;
}Possible Responses:
| Security Status | Message |
| :-------------: | -------------------------------------------------- |
| false | Location permission denied |
| false | Location services are disabled |
| false | Connected to an unsecured open Wi-Fi network |
| false | Connected to a weak security Wi-Fi network (WEP) |
| false | Connected to a Wi-Fi network using insecure WPS |
| false | Connected to a weak security Wi-Fi network (WPA-1) |
| true | Using mobile data or not connected to Wi-Fi |
| true | Wi-Fi information is unavailable |
| true | Connected to a secure Wi-Fi network |
🔐 Permissions
Android Permissions
Add these permissions to your AndroidManifest.xml:
iOS Permissions
Add these entries to your Info.plist:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Location permission is required to check Wi-Fi network security</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Location permission is required to check Wi-Fi network security</string>Additionally, enable the Access WiFi Information capability in your Xcode project:
- Open your project in Xcode
- Select your target
- Go to Signing & Capabilities
- Click + Capability
- Add Access WiFi Information
⚠️ Important Notes
Location Requirements:
- Location permission must be granted by the user
- Location services must be enabled on the device
- Without these, Wi-Fi details (SSID/BSSID) may be inaccessible
- The API may return limited or fallback results if requirements aren't met
🤝 Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
