passing access token for encryption for master key login as well

This commit is contained in:
Nouman Tahir 2021-06-28 23:56:25 +05:00
parent 101a4c7ac4
commit 2e20420337
2 changed files with 11 additions and 6 deletions

View File

@ -3,6 +3,8 @@ import Config from 'react-native-config';
import VersionNumber from 'react-native-version-number';
import { get } from 'lodash';
import { store } from '../redux/store/store';
import { getDigitPinCode } from '../providers/hive/dhive';
import { decryptKey } from '../utils/crypto';
const api = axios.create({
baseURL: Config.ECENCY_BACKEND_API,
@ -20,8 +22,13 @@ api.interceptors.request.use((request) => {
return request
}
//decrypt access token
const state = store.getState();
const accessToken = get(state, 'account.currentAccount.accessToken');
const token = get(state, 'account.currentAccount.local.accessToken');
const pin = get(state, 'application.pin');
const digitPinCode = getDigitPinCode(pin);
const accessToken = decryptKey(token, digitPinCode);
if (accessToken) {
if (!request.data) {
request.data = {};

View File

@ -104,6 +104,7 @@ export const login = async (username, password, isPinCodeOpen) => {
const resData = {
pinCode: Config.DEFAULT_PIN,
password,
accessToken: get(scTokens, 'access_token', ''),
};
const updatedUserData = await getUpdatedUserData(userData, resData);
@ -124,7 +125,6 @@ export const login = async (username, password, isPinCodeOpen) => {
return {
...account,
password,
accessToken: get(scTokens, 'access_token', ''),
};
}
return Promise.reject(new Error('auth.invalid_credentials'));
@ -382,10 +382,8 @@ export const getUpdatedUserData = (userData, data) => {
return {
username: get(userData, 'username', ''),
authType: get(userData, 'authType', ''),
accessToken:
get(userData, 'authType', '') === AUTH_TYPE.STEEM_CONNECT
? encryptKey(data.accessToken, get(data, 'pinCode'))
: '',
accessToken: encryptKey(data.accessToken, get(data, 'pinCode')),
masterKey:
get(userData, 'authType', '') === AUTH_TYPE.MASTER_KEY
? encryptKey(data.password, get(data, 'pinCode'))