import * as Keychain from 'react-native-keychain'; /** * Tries to recover login token from the secure keychain * * @returns Promise */ export async function retrieveLoginToken(): Promise { return new Promise((resolve: (token: string | undefined) => void) => { Keychain.getGenericPassword() .then((data: Keychain.UserCredentials | false) => { if (data && data.password) { resolve(data.password); } else { resolve(undefined); } }) .catch(() => resolve(undefined)); }); } /** * Saves the login token in the secure keychain * * @param email * @param token * @returns Promise */ export async function saveLoginToken( email: string, token: string ): Promise { return new Promise((resolve: () => void, reject: () => void) => { Keychain.setGenericPassword(email, token).then(resolve).catch(reject); }); } /** * Deletes the login token from the keychain * * @returns Promise */ export async function deleteLoginToken(): Promise { return new Promise((resolve: () => void, reject: () => void) => { Keychain.resetGenericPassword().then(resolve).catch(reject); }); }