Skip to content

Instantly share code, notes, and snippets.

@adhithiravi
Last active November 3, 2018 16:46
Show Gist options
  • Save adhithiravi/91c849dd5f2ad202bf8652c0050334cf to your computer and use it in GitHub Desktop.
Save adhithiravi/91c849dd5f2ad202bf8652c0050334cf to your computer and use it in GitHub Desktop.
import * as Keychain from 'react-native-keychain';
import DeviceInfo from 'react-native-device-info'
async () => {
const username = 'adhithi';
const password = 'poniesRgr8';
const server = DeviceInfo.getBundleId()
// Store the credentials
await Keychain.setInternetCredentials(server, email, password).then(() => {
try {
// Retreive the credentials
const credentials = await getInternetCredentials(server);
if (credentials) {
console.log('Credentials successfully loaded for user ' + credentials.username);
} else {
console.log('No credentials stored')
}
} catch (error) {
console.log('Keychain couldn\'t be accessed!', error);
}
await Keychain.resetInternetCredentials(server)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment