Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow clisk konnectors to have more context #1263

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/libs/ReactNativeLauncher.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,12 @@ class ReactNativeLauncher extends Launcher {
}

async _start({ initKonnectorError } = {}) {
const { account: prevAccount, konnector, client } = this.getStartContext()
const {
account: prevAccount,
konnector,
client,
trigger: contextTrigger
} = this.getStartContext()
await initialize(client)
if (flag('clisk.html-on-error')) {
Minilog.pipe(Minilog.backends.array)
Expand Down Expand Up @@ -324,13 +329,19 @@ class ReactNativeLauncher extends Launcher {

try {
this.setUserData(
await this.initAndCheckSourceAccountIdentifier(prevAccount)
await this.initAndCheckSourceAccountIdentifier({
account: prevAccount,
trigger: contextTrigger
})
)
} catch (err) {
if (err.message === 'WRONG_ACCOUNT_IDENTIFIER') {
await this.pilot.call('ensureNotAuthenticated')
this.setUserData(
await this.initAndCheckSourceAccountIdentifier(prevAccount)
await this.initAndCheckSourceAccountIdentifier({
account: prevAccount,
trigger: contextTrigger
})
)
} else {
throw err
Expand Down Expand Up @@ -397,14 +408,14 @@ class ReactNativeLauncher extends Launcher {
* @returns {Object}
* @throws 'WRONG_ACCOUNT_IDENTIFIER'
*/
async initAndCheckSourceAccountIdentifier(account) {
async initAndCheckSourceAccountIdentifier({ account, trigger }) {
this.log({
namespace: 'ReactNativeLauncher',
label: 'initAndCheckSourceAccountIdentifier',
level: 'debug',
msg: 'start'
})
await this.pilot.call('ensureAuthenticated', { account })
await this.pilot.call('ensureAuthenticated', { account, trigger })

const userDataResult = await this.pilot.call('getUserDataFromWebsite')

Expand Down
6 changes: 3 additions & 3 deletions src/libs/ReactNativeLauncher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ describe('ReactNativeLauncher', () => {
expect(launcher.pilot.call).toHaveBeenNthCalledWith(
2,
'ensureAuthenticated',
{ account: fixtures.account }
{ account: fixtures.account, trigger: fixtures.trigger }
)
expect(launcher.pilot.call).toHaveBeenNthCalledWith(
3,
Expand Down Expand Up @@ -522,7 +522,7 @@ describe('ReactNativeLauncher', () => {
expect(launcher.pilot.call).toHaveBeenNthCalledWith(
4,
'ensureAuthenticated',
{ account: fixtures.account }
{ account: fixtures.account, trigger: fixtures.trigger }
)
})
it('should not fail when clisk version is less than 0.10.0', async () => {
Expand Down Expand Up @@ -560,7 +560,7 @@ describe('ReactNativeLauncher', () => {
expect(launcher.pilot.call).toHaveBeenNthCalledWith(
3,
'ensureAuthenticated',
{ account: fixtures.account }
{ account: fixtures.account, trigger: fixtures.trigger }
)
})
it('should raise WRONG_ACCOUNT_IDENTIFIER when the user authenticates with the wrong identifiers twice', async () => {
Expand Down
Loading