react-native-keychain
Advanced tools
Comparing version 1.0.0 to 1.1.0
58
index.js
import { NativeModules, Platform } from 'react-native'; | ||
const { RNKeychainManager } = NativeModules; | ||
type SecAccessible = | ||
| 'AccessibleWhenUnlocked' | ||
| 'AccessibleAfterFirstUnlock' | ||
| 'AccessibleAlways' | ||
| 'AccessibleWhenPasscodeSetThisDeviceOnly' | ||
| 'AccessibleWhenUnlockedThisDeviceOnly' | ||
| 'AccessibleAfterFirstUnlockThisDeviceOnly' | ||
| 'AccessibleAlwaysThisDeviceOnly' | ||
type Options = { | ||
accessible?: SecAccessible; | ||
accessGroup?: string; | ||
service?: string; | ||
}; | ||
/** | ||
@@ -9,2 +24,3 @@ * Saves the `username` and `password` combination for `server`. | ||
* @param {string} password Associated password to be saved. | ||
* @param {object} options Keychain options, iOS only | ||
* @return {Promise} Resolves to `true` when successful | ||
@@ -15,5 +31,6 @@ */ | ||
username: string, | ||
password: string | ||
password: string, | ||
options?: Options | ||
): Promise { | ||
return RNKeychainManager.setInternetCredentialsForServer(server, username, password); | ||
return RNKeychainManager.setInternetCredentialsForServer(server, username, password, options); | ||
} | ||
@@ -24,8 +41,10 @@ | ||
* @param {string} server URL to server. | ||
* @param {object} options Keychain options, iOS only | ||
* @return {Promise} Resolves to `{ server, username, password }` when successful | ||
*/ | ||
export function getInternetCredentials( | ||
server: string | ||
server: string, | ||
options?: Options | ||
): Promise { | ||
return RNKeychainManager.getInternetCredentialsForServer(server); | ||
return RNKeychainManager.getInternetCredentialsForServer(server, options); | ||
} | ||
@@ -36,10 +55,19 @@ | ||
* @param {string} server URL to server. | ||
* @param {object} options Keychain options, iOS only | ||
* @return {Promise} Resolves to `true` when successful | ||
*/ | ||
export function resetInternetCredentials( | ||
server: string | ||
server: string, | ||
options?: Options | ||
): Promise { | ||
return RNKeychainManager.resetInternetCredentialsForServer(server); | ||
return RNKeychainManager.resetInternetCredentialsForServer(server, options); | ||
} | ||
function getOptionsArgument(serviceOrOptions?: string | KeychainOptions) { | ||
if (Platform.OS !== 'ios') { | ||
return typeof serviceOrOptions === 'object' ? serviceOrOptions.service : serviceOrOptions; | ||
} | ||
return typeof serviceOrOptions === 'string' ? { service: serviceOrOptions } : serviceOrOptions; | ||
} | ||
/** | ||
@@ -49,3 +77,3 @@ * Saves the `username` and `password` combination for `service`. | ||
* @param {string} password Associated password to be saved. | ||
* @param {string} service Reverse domain name qualifier for the service, defaults to `bundleId`. | ||
* @param {string|object} serviceOrOptions Reverse domain name qualifier for the service, defaults to `bundleId` or an options object. | ||
* @return {Promise} Resolves to `true` when successful | ||
@@ -56,5 +84,5 @@ */ | ||
password: string, | ||
service?: string | ||
serviceOrOptions?: string | KeychainOptions | ||
): Promise { | ||
return RNKeychainManager.setGenericPasswordForService(service, username, password); | ||
return RNKeychainManager.setGenericPasswordForOptions(getOptionsArgument(serviceOrOptions), username, password); | ||
} | ||
@@ -64,9 +92,9 @@ | ||
* Fetches login combination for `service`. | ||
* @param {string} service Reverse domain name qualifier for the service, defaults to `bundleId`. | ||
* @param {string|object} serviceOrOptions Reverse domain name qualifier for the service, defaults to `bundleId` or an options object. | ||
* @return {Promise} Resolves to `{ service, username, password }` when successful | ||
*/ | ||
export function getGenericPassword( | ||
service?: string | ||
serviceOrOptions?: string | KeychainOptions | ||
): Promise { | ||
return RNKeychainManager.getGenericPasswordForService(service); | ||
return RNKeychainManager.getGenericPasswordForOptions(getOptionsArgument(serviceOrOptions)); | ||
} | ||
@@ -76,9 +104,9 @@ | ||
* Deletes all generic password keychain entries for `service`. | ||
* @param {string} service Reverse domain name qualifier for the service, defaults to `bundleId`. | ||
* @param {string|object} serviceOrOptions Reverse domain name qualifier for the service, defaults to `bundleId` or an options object. | ||
* @return {Promise} Resolves to `true` when successful | ||
*/ | ||
export function resetGenericPassword( | ||
service?: string | ||
serviceOrOptions?: string | KeychainOptions | ||
): Promise { | ||
return RNKeychainManager.resetGenericPasswordForService(service); | ||
return RNKeychainManager.resetGenericPasswordForOptions(getOptionsArgument(serviceOrOptions)); | ||
} | ||
@@ -85,0 +113,0 @@ |
{ | ||
"name": "react-native-keychain", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Keychain Access for React Native", | ||
@@ -5,0 +5,0 @@ "main": "index", |
@@ -85,3 +85,5 @@ # react-native-keychain | ||
.then(function(credentials) { | ||
console.log('Credentials successfully loaded for user ' + credentials.username); | ||
if (credentials) { | ||
console.log('Credentials successfully loaded for user ' + credentials.username); | ||
} | ||
}); | ||
@@ -88,0 +90,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
173021
160
177
0