diff --git a/sharedExample/src/ContentpassUsage.tsx b/sharedExample/src/ContentpassUsage.tsx index 4f52427..f136fd9 100644 --- a/sharedExample/src/ContentpassUsage.tsx +++ b/sharedExample/src/ContentpassUsage.tsx @@ -49,7 +49,16 @@ export default function ContentpassUsage() { spConsentManager.current?.onAction((action) => { if (action.customActionId === "cp('login')") { - contentpassSdk.authenticate(); + contentpassSdk + .authenticate() + .then(() => { + // eslint-disable-next-line no-console + console.log('Successfully authenticated'); + }) + .catch((err) => { + // eslint-disable-next-line no-console + console.error('Failed to authenticate:', err); + }); } }); diff --git a/src/Contentpass.test.ts b/src/Contentpass.test.ts index 0a7aad7..c2e63e3 100644 --- a/src/Contentpass.test.ts +++ b/src/Contentpass.test.ts @@ -177,7 +177,9 @@ describe('Contentpass', () => { contentpassStates.push(state); }); - await contentpass.authenticate(); + await expect(async () => { + await contentpass.authenticate(); + }).rejects.toThrow(error); expect(reportErrorSpy).toHaveBeenCalledWith(error, { msg: 'Failed to authorize', @@ -241,10 +243,10 @@ describe('Contentpass', () => { ).getTime(); const expectedDelay = expirationDate - NOW; - expect(refreshSpy).toBeCalledTimes(0); + expect(refreshSpy).toHaveBeenCalledTimes(0); jest.advanceTimersByTime(expectedDelay); - expect(refreshSpy).toBeCalledTimes(1); - expect(refreshSpy).toBeCalledWith( + expect(refreshSpy).toHaveBeenCalledTimes(1); + expect(refreshSpy).toHaveBeenCalledWith( { clientId: 'propertyId-1', redirectUrl: 'de.test.net://oauth', @@ -274,7 +276,7 @@ describe('Contentpass', () => { await contentpass.authenticate(); - expect(refreshSpy).toBeCalledTimes(0); + expect(refreshSpy).toHaveBeenCalledTimes(0); expect(contentpassStates).toHaveLength(2); expect(contentpassStates[1]).toEqual({ @@ -414,8 +416,9 @@ describe('Contentpass', () => { const error = new Error('Authorize error'); authorizeSpy.mockRejectedValue(error); - await contentpass.authenticate(); - + await expect(async () => { + await contentpass.authenticate(); + }).rejects.toThrow(error); expect(contentpassStates[1]).toEqual({ state: 'ERROR', error, diff --git a/src/Contentpass.ts b/src/Contentpass.ts index e3cc434..413e1d0 100644 --- a/src/Contentpass.ts +++ b/src/Contentpass.ts @@ -54,12 +54,12 @@ export default class Contentpass { }); } catch (err: any) { reportError(err, { msg: 'Failed to authorize' }); - this.changeContentpassState({ state: ContentpassStateType.ERROR, error: err, }); - return; + + throw err; } await this.onNewAuthState(result);