diff --git a/examples/client/Locomotion/src/context/user/index.tsx b/examples/client/Locomotion/src/context/user/index.tsx index 8e4e9505e..965608a83 100644 --- a/examples/client/Locomotion/src/context/user/index.tsx +++ b/examples/client/Locomotion/src/context/user/index.tsx @@ -173,13 +173,32 @@ const UserContextProvider = ({ children }: { children: any }) => { return vertResponse.status === 'OK'; }; + const getAllowedDemandSourceIds = (): string[] => { + try { + if (!Config.ALLOWED_DEMAND_SOURCE_IDS) { + return []; + } + const allowedDemandSourceIds = JSON.parse(Config.ALLOWED_DEMAND_SOURCE_IDS); + return Array.isArray(allowedDemandSourceIds) ? allowedDemandSourceIds : []; + } catch (error) { + Mixpanel.setEvent('Invalid ALLOWED_DEMAND_SOURCE_IDS', { allowedDemandSourceIds: Config.ALLOWED_DEMAND_SOURCE_IDS }); + return []; + } + }; + const onLogin = async (phoneNumber: string, channel = 'sms') => { const demandSourceId = await AppSettings.getOperationId(); - await loginApi({ + const allowedDemandSourceIds = getAllowedDemandSourceIds(); + const response = await loginApi({ phoneNumber, channel, demandSourceId, + allowedDemandSourceIds, }); + const { selectedDemandSourceId } = response; + if (allowedDemandSourceIds.length > 0 && selectedDemandSourceId && selectedDemandSourceId !== demandSourceId) { + await AppSettings.setOperationId(selectedDemandSourceId); + } // successful login - delete captcha token await StorageService.delete('captchaToken'); }; diff --git a/examples/client/Locomotion/src/services/app-settings.js b/examples/client/Locomotion/src/services/app-settings.js index 0dc4cef38..13e1a922e 100644 --- a/examples/client/Locomotion/src/services/app-settings.js +++ b/examples/client/Locomotion/src/services/app-settings.js @@ -31,6 +31,7 @@ const AppSettings = { }, }); }, + setOperationId: async newOperationId => AppSettings.setSettings({ operationId: newOperationId }), destroy: async () => Storage.clear(), };