Testing steemconnect login

This commit is contained in:
mistikk 2018-10-23 01:09:29 +03:00
parent d705aa631c
commit 02816243e0
3 changed files with 27 additions and 3 deletions

View File

@ -122,14 +122,17 @@ export const setUserDataWithPinCode = data => new Promise((resolve, reject) => {
resolve();
})
.catch((error) => {
console.log('======1',error);
reject(error);
});
})
.catch((error) => {
console.log('======2',error);
reject(error);
});
})
.catch((err) => {
console.log('======3',err);
reject(err);
});
resolve();
@ -139,16 +142,23 @@ export const verifyPinCode = data => new Promise((resolve, reject) => {
const result = getUserDataWithUsername(data.username);
const userData = result[0];
let loginFlag = false;
console.log('userData',userData);
console.log('data',data);
if (userData.masterKey || userData.accessToken) {
const masterKey = decryptKey(userData.masterKey, data.pinCode);
const accessToken = decryptKey(userData.accessToken, data.pinCode);
console.log('masterKey',masterKey);
console.log('accessToken',accessToken);
if (masterKey === data.password || accessToken === data.accessToken) {
loginFlag = true;
}
} else if (data.accessToken) {
console.log('data.accessToken',data.accessToken);
getPinCode()
.then((encriptedPinCode) => {
console.log('encriptedPinCode',encriptedPinCode);
const pinCode = decryptKey(encriptedPinCode, 'pin-code');
console.log('pinCode',pinCode);
if (pinCode === data.pinCode) {
loginFlag = true;
}

View File

@ -25,7 +25,9 @@ const authSchema = {
},
};
const realm = new Realm({ schema: [userSchema, authSchema] });
const realm = new Realm({ path: 'test.realm', schema: [userSchema, authSchema] });
console.log('=========path=========', realm.path, Realm.defaultPath);
// TODO: This is getting ALL user data, we should change this method with getUserDataWithUsername
export const getUserData = () => new Promise((resolve, reject) => {
@ -115,9 +117,20 @@ export const getAuthStatus = () => new Promise((resolve, reject) => {
export const setAuthStatus = authStatus => new Promise((resolve, reject) => {
try {
const auth = realm.objects(AUTH_SCHEMA);
const test = Array.from(auth);
const test1 = Array.from(auth).length;
console.log('========1=======',test,test1);
realm.write(() => {
auth[0].isLoggedIn = authStatus.isLoggedIn;
resolve(auth[0]);
if (Array.from(auth).length > 0) {
auth[0].isLoggedIn = authStatus.isLoggedIn;
console.log('========1=======');
resolve(auth[0]);
} else {
realm.create(AUTH_SCHEMA, { ...authStatus, pinCode: '' });
console.log('========2=======');
resolve(authStatus);
}
});
} catch (error) {
reject(error);

View File

@ -29,6 +29,7 @@ class SteemConnect extends Component {
// this.webview.stopLoading();
try {
accessToken = event.url.match(/\?(?:access_token)\=([\S\s]*?)\&/)[1];
console.log('accesstoken',accessToken);
} catch (error) {
console.log(error);
}