diff --git a/index.js b/index.js index 947b3fcb..463c6411 100755 --- a/index.js +++ b/index.js @@ -142,16 +142,22 @@ exports.login = async function(options) { // check that the key got added const near = await connect(options); let account = await near.account(accountId); - let state = await account.state(); - if (state.public_keys.includes(keyPair.getPublicKey())) { + let keys = await account.getAccessKeys(); + let keyFound = false; + for (let i = 0; i < keys.length; i++) { + if (keys[i].public_key == keyPair.getPublicKey()) { + keyFound = true; + } + } + if (keyFound) { const keyStore = new UnencryptedFileSystemKeyStore('./neardev'); keyStore.setKey(options.networkId, accountId, keyPair); console.log(`Logged in with ${accountId}`); } else { console.log('Log in did not succeed. Please try again.') } - } catch (_) { - console.log('Log in did not succeed. Please try again.') + } catch (e) { + console.log(e) } rl.close(); });