Skip to content

Commit

Permalink
feat(sso): authorize device from exchange email trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLeoB committed Dec 7, 2021
1 parent 670d48e commit c5b610c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
4 changes: 2 additions & 2 deletions packages/blockchain-wallet-v4-frontend/src/data/auth/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,13 +715,13 @@ export default ({ api, coreSagas, networks }) => {

const authorizeVerifyDevice = function* (action) {
const confirmDevice = action.payload
const { wallet } = yield select(selectors.auth.getMagicLinkData)
const { session_id } = yield select(selectors.auth.getMagicLinkData)
const magicLinkDataEncoded = yield select(selectors.auth.getMagicLinkDataEncoded)
try {
yield put(actions.auth.authorizeVerifyDeviceLoading())
const data = yield call(
api.authorizeVerifyDevice,
wallet.session_id,
session_id,
magicLinkDataEncoded,
confirmDevice
)
Expand Down
46 changes: 22 additions & 24 deletions packages/blockchain-wallet-v4-frontend/src/data/auth/sagas.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ export const parseMagicLink = function* () {
productAuth = ProductAuthOptions.WALLET
}
}
if (session !== session_id && shouldPollForMagicLinkData) {
yield put(actions.auth.authorizeVerifyDevice())
yield put(actions.form.change('login', 'step', LoginSteps.VERIFY_MAGIC_LINK))
}
// THESE ARE THE MERGE AND UPGRADE FLOWS
//
if (showMergeAndUpradeFlows) {
Expand All @@ -71,12 +67,11 @@ export const parseMagicLink = function* () {
actions.auth.setAccountUnificationFlowType(AccountUnificationFlows.EXCHANGE_UPGRADE)
)
}
} else if (unified) {
actions.auth.setAccountUnificationFlowType(AccountUnificationFlows.UNIFIED)
}
}
// TODDO: WRAP ABOVE IN FEATURE FLAG
if (unified) {
actions.auth.setAccountUnificationFlowType(AccountUnificationFlows.UNIFIED)
}

// store data in the cache and update form values to be used to submit login
if (productAuth === ProductAuthOptions.WALLET) {
Expand Down Expand Up @@ -105,26 +100,29 @@ export const parseMagicLink = function* () {
}
}
if (productAuth === ProductAuthOptions.EXCHANGE) {
// set state with all exchange login information
yield put(actions.cache.emailStored(exchangeData?.email))
yield put(actions.form.change(LOGIN_FORM, 'email', userEmail))
if (walletData) {
yield put(actions.form.change(LOGIN_FORM, 'emailToken', walletData?.email_code))
yield put(actions.form.change(LOGIN_FORM, 'guid', walletData?.guid))
}
yield put(actions.auth.setMagicLinkInfo(magicLink))
yield put(
actions.auth.setProductAuthMetadata({
platform: PlatformTypes.WEB,
product: ProductAuthOptions.EXCHANGE
})
)
// if the account is unified, they're using wallet to login and retrieve token
if (unified) {
yield put(actions.form.change(LOGIN_FORM, 'step', LoginSteps.ENTER_PASSWORD_WALLET))
if (session !== session_id && shouldPollForMagicLinkData) {
// TODO: question for merge, do we need the next line?
yield put(actions.auth.authorizeVerifyDevice())
yield put(actions.form.change(LOGIN_FORM, 'step', LoginSteps.VERIFY_MAGIC_LINK))
} else {
// set state with all exchange login information
yield put(actions.cache.emailStored(exchangeData?.email))
yield put(actions.form.change(LOGIN_FORM, 'email', userEmail))
if (walletData) {
yield put(actions.form.change(LOGIN_FORM, 'emailToken', walletData?.email_code))
yield put(actions.form.change(LOGIN_FORM, 'guid', walletData?.guid))
}
yield put(actions.auth.setMagicLinkInfo(magicLink))
yield put(
actions.auth.setProductAuthMetadata({
platform: PlatformTypes.WEB,
product: ProductAuthOptions.EXCHANGE
})
)
yield put(actions.form.change(LOGIN_FORM, 'step', LoginSteps.ENTER_PASSWORD_EXCHANGE))
}
// if the account is unified, they're using wallet to login and retrieve token
// TODO** need to fix logic here, not sure what to do with this
}
yield put(actions.auth.analyticsMagicLinkParsed())
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ const Error = (props) => {
<ErrorWrapper>
<Icon color='error' name='close-circle' size='40px' />
<Text size='20px' weight={600} color='black' style={{ marginTop: '8px' }}>
{error.request_denied ? (
{error?.request_denied ? (
<FormattedMessage
id='scenes.login.device_verification_rejected'
defaultMessage='Device verification rejected.'
/>
) : error.link_expired ? (
) : error?.link_expired ? (
<FormattedMessage
id='scenes.login.device_verification_expired'
defaultMessage='Verification link expired.'
Expand All @@ -33,12 +33,12 @@ const Error = (props) => {
)}
</Text>
<Text style={{ margin: '8px 0 12px' }} size='16px' color='red600' weight={500}>
{error.request_denied ? (
{error?.request_denied ? (
<FormattedMessage
id='scenes.authorizelogin.loading.rejected.content'
defaultMessage='Please contact our support team if you have any questions or concerns.'
/>
) : error.link_expired ? (
) : error?.link_expired ? (
<FormattedMessage
id='scenes.login._device_verification_expired.copy'
defaultMessage='The device approval link has expired, please try again.'
Expand Down

0 comments on commit c5b610c

Please sign in to comment.