Skip to content

Keychain Module

The Keychain module securely stores and retrieves a username/password pair on the device.

import { Keychain } from '@shopgate/native-modules';
import { useState } from 'react';
import { Keychain } from '@shopgate/native-modules';
export function LoginStorage() {
const [username, setUsername] = useState(null);
const loadLogin = async () => {
const credentials = await Keychain.getLogin();
setUsername(credentials ? credentials.username : null);
};
return <button type="button" onClick={loadLogin}>{username ?? 'Load login'}</button>;
}
await Keychain.setLogin('user@example.com', 'password');
const credentials = await Keychain.getLogin();

Returns { username, password } or false when no credentials exist.

await Keychain.resetLogin();

setLogin() and resetLogin() resolve when complete.