Skip to content

Commit

Permalink
feat: Allow clisk konnectors to have more context
Browse files Browse the repository at this point in the history
In ensureAuthenticated method, clisk konnectors now also get current
trigger when available.
  • Loading branch information
doubleface committed Nov 19, 2024
1 parent f05bd13 commit 76d922a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
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

0 comments on commit 76d922a

Please sign in to comment.