Skip to content

Commit caf8f70

Browse files
authored
chore(passport): ID-3992 Headless login doc changes (#2710)
1 parent e6693bf commit caf8f70

3 files changed

Lines changed: 36 additions & 8 deletions

File tree

examples/passport/setup-with-nextjs/src/app/utils/setupDefault.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const passportInstanceWithDisabledOverlays = new passport.Passport({
2727
popupOverlayOptions: {
2828
disableGenericPopupOverlay: true,
2929
disableBlockedPopupOverlay: true,
30+
disableHeadlessLoginPromptOverlay: true,
3031
},
3132
});
3233

packages/passport/sdk/src/authManager.test.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,26 +1045,38 @@ describe('AuthManager', () => {
10451045

10461046
it('should include direct parameter when directLoginMethod is provided', async () => {
10471047
const directLoginMethod = 'apple';
1048-
const result = await authManager.getPKCEAuthorizationUrl({ directLoginMethod });
1048+
const result = await authManager.getPKCEAuthorizationUrl({
1049+
directLoginMethod,
1050+
marketingConsentStatus: MarketingConsentStatus.OptedIn,
1051+
});
10491052
const url = new URL(result);
10501053

10511054
expect(url.searchParams.get('direct')).toEqual('apple');
1055+
expect(url.searchParams.get('marketingConsent')).toEqual(MarketingConsentStatus.OptedIn);
10521056
});
10531057

10541058
it('should include direct parameter for google login method', async () => {
10551059
const directLoginMethod = 'google';
1056-
const result = await authManager.getPKCEAuthorizationUrl({ directLoginMethod });
1060+
const result = await authManager.getPKCEAuthorizationUrl({
1061+
directLoginMethod,
1062+
marketingConsentStatus: MarketingConsentStatus.OptedIn,
1063+
});
10571064
const url = new URL(result);
10581065

10591066
expect(url.searchParams.get('direct')).toEqual('google');
1067+
expect(url.searchParams.get('marketingConsent')).toEqual(MarketingConsentStatus.OptedIn);
10601068
});
10611069

10621070
it('should include direct parameter for facebook login method', async () => {
10631071
const directLoginMethod = 'facebook';
1064-
const result = await authManager.getPKCEAuthorizationUrl({ directLoginMethod });
1072+
const result = await authManager.getPKCEAuthorizationUrl({
1073+
directLoginMethod,
1074+
marketingConsentStatus: MarketingConsentStatus.OptedIn,
1075+
});
10651076
const url = new URL(result);
10661077

10671078
expect(url.searchParams.get('direct')).toEqual('facebook');
1079+
expect(url.searchParams.get('marketingConsent')).toEqual(MarketingConsentStatus.OptedIn);
10681080
});
10691081

10701082
it('should include audience parameter when specified in config', async () => {
@@ -1081,7 +1093,10 @@ describe('AuthManager', () => {
10811093
const configWithAudience = getConfig({ audience: 'test-audience' });
10821094
const am = new AuthManager(configWithAudience, mockEmbeddedLoginPrompt);
10831095

1084-
const result = await am.getPKCEAuthorizationUrl({ directLoginMethod: 'apple', marketingConsentStatus: MarketingConsentStatus.OptedIn });
1096+
const result = await am.getPKCEAuthorizationUrl({
1097+
directLoginMethod: 'apple',
1098+
marketingConsentStatus: MarketingConsentStatus.OptedIn,
1099+
});
10851100
const url = new URL(result);
10861101

10871102
expect(url.searchParams.get('direct')).toEqual('apple');
@@ -1101,13 +1116,17 @@ describe('AuthManager', () => {
11011116
it('should pass directLoginMethod to login popup', async () => {
11021117
mockSigninPopup.mockResolvedValue(mockOidcUser);
11031118

1104-
await authManager.login('anonymous-id', { directLoginMethod: 'apple' });
1119+
await authManager.login('anonymous-id', {
1120+
directLoginMethod: 'apple',
1121+
marketingConsentStatus: MarketingConsentStatus.OptedIn,
1122+
});
11051123

11061124
expect(mockSigninPopup).toHaveBeenCalledWith({
11071125
extraQueryParams: {
11081126
rid: '',
11091127
third_party_a_id: 'anonymous-id',
11101128
direct: 'apple',
1129+
marketingConsent: MarketingConsentStatus.OptedIn,
11111130
},
11121131
popupWindowFeatures: {
11131132
width: 410,
@@ -1158,13 +1177,17 @@ describe('AuthManager', () => {
11581177
});
11591178

11601179
it('should pass directLoginMethod to redirect login', async () => {
1161-
await authManager.loginWithRedirect('anonymous-id', { directLoginMethod: 'google' });
1180+
await authManager.loginWithRedirect('anonymous-id', {
1181+
directLoginMethod: 'google',
1182+
marketingConsentStatus: MarketingConsentStatus.OptedIn,
1183+
});
11621184

11631185
expect(mockSigninRedirect).toHaveBeenCalledWith({
11641186
extraQueryParams: {
11651187
rid: '',
11661188
third_party_a_id: 'anonymous-id',
11671189
direct: 'google',
1190+
marketingConsent: MarketingConsentStatus.OptedIn,
11681191
},
11691192
});
11701193
});
@@ -1223,14 +1246,18 @@ describe('AuthManager', () => {
12231246
it('should not call displayEmbeddedLoginPrompt when directLoginOptions are provided', async () => {
12241247
mockSigninPopup.mockResolvedValue(mockOidcUser);
12251248

1226-
await authManager.login('anonymous-id', { directLoginMethod: 'apple' });
1249+
await authManager.login('anonymous-id', {
1250+
directLoginMethod: 'apple',
1251+
marketingConsentStatus: MarketingConsentStatus.OptedIn,
1252+
});
12271253

12281254
expect(mockEmbeddedLoginPrompt.displayEmbeddedLoginPrompt).not.toHaveBeenCalled();
12291255
expect(mockSigninPopup).toHaveBeenCalledWith({
12301256
extraQueryParams: {
12311257
rid: '',
12321258
third_party_a_id: 'anonymous-id',
12331259
direct: 'apple',
1260+
marketingConsent: MarketingConsentStatus.OptedIn,
12341261
},
12351262
popupWindowFeatures: {
12361263
width: 410,

packages/passport/sdk/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export enum MarketingConsentStatus {
184184
}
185185

186186
export type DirectLoginOptions = {
187-
marketingConsentStatus?: MarketingConsentStatus;
187+
marketingConsentStatus: MarketingConsentStatus;
188188
} & (
189189
| { directLoginMethod: 'email'; email: string }
190190
| { directLoginMethod: Exclude<DirectLoginMethod, 'email'>; email?: never }

0 commit comments

Comments
 (0)