Skip to content

Commit

Permalink
feat(sso): updated exchange only magic link data
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLeoB committed Nov 15, 2021
1 parent cb1f3d7 commit f566f10
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ export const parseMagicLink = function* () {
exchange: exchangeData,
mergeable,
product,
session_id,
unified,
upgradeable,
wallet: walletData
} = magicLink
const session = yield select(selectors.session.getSession, walletData?.guid, walletData?.email)
const sessionIdFromLink = walletData?.session_id
const session = yield select(
selectors.session.getSession,
walletData?.guid,
walletData?.email || exchangeData?.email
)
// remove feature flag when not necessary
const shouldPollForMagicLinkData = (yield select(
selectors.core.walletOptions.getPollForMagicLinkData
Expand All @@ -39,7 +43,7 @@ export const parseMagicLink = function* () {
productAuth = ProductAuthOptions.WALLET
}
}
if (session !== sessionIdFromLink && shouldPollForMagicLinkData) {
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', 'step', LoginSteps.VERIFY_MAGIC_LINK))
Expand Down Expand Up @@ -68,7 +72,7 @@ export const parseMagicLink = function* () {

// store data in the cache and update form values to be used to submit login
if (productAuth === ProductAuthOptions.WALLET) {
if (session !== sessionIdFromLink && shouldPollForMagicLinkData) {
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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ export type WalletDataFromMagicLink = {
twoFaMode?: boolean
user_id?: string
}
exchange_auth_url?: string
mergeable?: boolean | null
product?: ProductAuthOptions
session_id?: string
unified?: boolean
upgradeable?: boolean | null
user_type?: UserType
Expand All @@ -138,7 +140,6 @@ export type WalletDataFromMagicLink = {
recovery_token?: string
user_id?: string
}
session_id?: string
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import { Props } from '../../index'
import { CenteredColumn, LoginWrapper } from '../../model'

const UpgradeSuccess = (props: Props) => {
const { product, redirect } = props.productAuthMetadata
const exchangeRedirect = decodeURIComponent(redirect as string)

const { magicLinkData, productAuthMetadata } = props
return (
<LoginWrapper>
<CenteredColumn style={{ textAlign: 'center' }}>
Expand All @@ -27,7 +25,7 @@ const UpgradeSuccess = (props: Props) => {
defaultMessage='You can now use your Wallet email and password to log in to your Blockchain.com Wallet and the Exchange.'
/>
</Text>
{product === ProductAuthOptions.WALLET && (
{productAuthMetadata.product === ProductAuthOptions.WALLET && (
<Button
nature='primary'
fullwidth
Expand All @@ -39,7 +37,7 @@ const UpgradeSuccess = (props: Props) => {
<FormattedMessage id='buttons.i_understand' defaultMessage='I Understand' />
</Button>
)}
{product === ProductAuthOptions.EXCHANGE && (
{productAuthMetadata.product === ProductAuthOptions.EXCHANGE && (
<Button
nature='primary'
fullwidth
Expand All @@ -48,7 +46,7 @@ const UpgradeSuccess = (props: Props) => {
style={{ marginTop: '16px' }}
>
<Link
href={`${exchangeRedirect}/auth?jwt=${props.jwtToken}`}
href={`${magicLinkData?.exchange_auth_url}${props.jwtToken}`}
rel='noopener noreferrer'
target='_blank'
color='white'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
LoginFormType,
LoginSteps,
PlatformTypes,
ProductAuthOptions
ProductAuthOptions,
WalletDataFromMagicLink
} from 'data/types'

// step templates
Expand Down Expand Up @@ -194,6 +195,7 @@ const mapStateToProps = (state) => ({
step: LoginSteps.ENTER_EMAIL_GUID
},
jwtToken: selectors.auth.getJwtToken(state),
magicLinkData: selectors.auth.getMagicLinkData(state),
productAuthMetadata: selectors.auth.getProductAuthMetadata(state),
walletLoginData: selectors.auth.getLogin(state) as RemoteDataType<any, any>
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const getData = (state: RootState) => {
const exchangeLoginR = selectors.auth.getExchangeLogin(state)
const jwtToken = selectors.auth.getJwtToken(state)
const language = selectors.preferences.getLanguage(state)
const magicLinkData = selectors.auth.getMagicLinkData(state)
const productAuthMetadata = selectors.auth.getProductAuthMetadata(state)
const walletLoginR = selectors.auth.getLogin(state)

Expand All @@ -28,6 +29,7 @@ export const getData = (state: RootState) => {
formValues,
jwtToken,
language,
magicLinkData,
productAuthMetadata,
walletLogin
})
Expand Down

0 comments on commit f566f10

Please sign in to comment.