Skip to content

Commit

Permalink
Merge pull request #3484 from blockchain/fix/2fa-session
Browse files Browse the repository at this point in the history
hotfix(login-2fa): setting new session token with 2fa login
  • Loading branch information
schnogz authored Aug 18, 2021
2 parents 749c2e4 + 251df0e commit 7281110
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export const setResetAccount = (resetAccount) => ({
type: AT.SET_RESET_ACCOUNT
})
// 2FA
export const resendSmsCode = (guid) => ({
payload: { guid },
export const resendSmsCode = (guid, email) => ({
payload: { email, guid },
type: AT.RESEND_SMS_CODE
})

Expand Down
11 changes: 6 additions & 5 deletions packages/blockchain-wallet-v4-frontend/src/data/auth/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,13 @@ export default ({ api, coreSagas, networks }) => {
const { code, guid, password, sharedKey } = action.payload
const formValues = yield select(selectors.form.getFormValues('login'))
const { email, emailToken } = formValues
let session = yield select(selectors.session.getSession, email || guid)
let session = yield select(selectors.session.getSession, guid, email)
yield put(startSubmit('login'))
try {
if (!session) {
session = yield call(api.obtainSessionToken)
yield put(actions.session.saveSession(assoc(guid, session, {})))
}
yield put(actions.session.saveSession(assoc(guid, session, {})))
yield put(actions.auth.loginLoading())
yield call(coreSagas.wallet.fetchWalletSaga, {
code,
Expand Down Expand Up @@ -559,8 +559,8 @@ export default ({ api, coreSagas, networks }) => {

const resendSmsLoginCode = function* (action) {
try {
const { guid } = action.payload
const sessionToken = yield select(selectors.session.getSession, guid)
const { email, guid } = action.payload
const sessionToken = yield select(selectors.session.getSession, guid, email)
const response = yield call(coreSagas.wallet.resendSmsLoginCode, {
guid,
sessionToken
Expand All @@ -579,7 +579,8 @@ export default ({ api, coreSagas, networks }) => {
const deauthorizeBrowser = function* () {
try {
const guid = yield select(selectors.core.wallet.getGuid)
const sessionToken = yield select(selectors.session.getSession, guid)
const email = (yield select(selectors.core.settings.getEmail)).getOrElse(undefined)
const sessionToken = yield select(selectors.session.getSession, guid, email)
yield call(api.deauthorizeBrowser, sessionToken)
yield put(actions.alerts.displaySuccess(C.DEAUTHORIZE_BROWSER_SUCCESS))
yield put(actions.cache.disconnectChannelPhone())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { curry, path } from 'ramda'
import { curry, defaultTo, path } from 'ramda'

export const getSession = curry((state, guid) => path(['session', guid], state))
export const getSession = curry((state, guid, email) => {
const guidSession = path(['session', guid], state)
const emailSession = path(['session', email], state)
return defaultTo(emailSession)(guidSession)
})
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '../model'

const EnterPassword = (props: Props) => {
const { authType, busy, formActions, guid, invalid, loginError, password, submitting } = props
const { authType, busy, formValues, guid, invalid, loginError, password, submitting } = props
const passwordError = loginError && loginError.toLowerCase().includes('wrong_wallet_password')
const accountLocked =
loginError &&
Expand All @@ -31,7 +31,7 @@ const EnterPassword = (props: Props) => {

const twoFactorError = loginError && loginError.toLowerCase().includes('authentication code')
const handleSmsResend = () => {
props.authActions.resendSmsCode(guid)
props.authActions.resendSmsCode(guid, formValues?.email)
}

const handleBackArrowClick = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Login extends PureComponent<InjectedFormProps<{}, Props> & Props, StatePro
}

handleSmsResend = () => {
this.props.authActions.resendSmsCode(this.props.guid)
this.props.authActions.resendSmsCode(this.props.guid, this.props.formValues?.email)
}

continueLoginProcess = () => {
Expand Down

0 comments on commit 7281110

Please sign in to comment.