Skip to content

Commit a6c0c85

Browse files
committed
Merge branch 'main' into ID-3893/passport-marketing-consent
2 parents b96dd12 + 6b65780 commit a6c0c85

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

packages/passport/sdk/src/Passport.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { PassportImxProviderFactory } from './starkEx';
1616
import { PassportConfiguration } from './config';
1717
import {
1818
DirectLoginOptions,
19+
DeviceTokenResponse,
1920
isUserImx,
2021
isUserZkEvm,
2122
LinkedWallet,
@@ -192,7 +193,7 @@ export class Passport {
192193
* Note: This takes precedence over useCachedSession if both are true
193194
* @param {boolean} [options.useRedirectFlow] - If true, uses redirect flow instead of popup flow
194195
* @param {DirectLoginOptions} [options.directLoginOptions] - If provided, contains login method and marketing consent options
195-
* @param {DirectLoginMethod} [options.directLoginOptions.directLoginMethod] - The login method to use (e.g., 'google', 'apple', 'email')
196+
* @param {string} [options.directLoginOptions.directLoginMethod] - The login method to use (e.g., 'google', 'apple', 'email')
196197
* @param {MarketingConsentStatus} [options.directLoginOptions.marketingConsentStatus] - Marketing consent status ('opted_in' or 'unsubscribed')
197198
* @param {string} [options.directLoginOptions.email] - Required when directLoginMethod is 'email'
198199
* @returns {Promise<UserProfile | null>} A promise that resolves to the user profile if logged in, null otherwise
@@ -305,6 +306,14 @@ export class Passport {
305306
}, 'loginWithPKCEFlowCallback');
306307
}
307308

309+
public async storeTokens(tokenResponse: DeviceTokenResponse): Promise<UserProfile> {
310+
return withMetricsAsync(async () => {
311+
const user = await this.authManager.storeTokens(tokenResponse);
312+
this.passportEventEmitter.emit(PassportEvents.LOGGED_IN, user);
313+
return user.profile;
314+
}, 'storeTokens');
315+
}
316+
308317
/**
309318
* Logs out the current user.
310319
* @returns {Promise<void>} A promise that resolves when the logout is complete

packages/passport/sdk/src/authManager.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,16 @@ export default class AuthManager {
392392
return response.data;
393393
}
394394

395+
public async storeTokens(tokenResponse: DeviceTokenResponse): Promise<User> {
396+
return withPassportError<User>(async () => {
397+
const oidcUser = AuthManager.mapDeviceTokenResponseToOidcUser(tokenResponse);
398+
const user = AuthManager.mapOidcUserToDomainModel(oidcUser);
399+
await this.userManager.storeUser(oidcUser);
400+
401+
return user;
402+
}, PassportErrorType.AUTHENTICATION_ERROR);
403+
}
404+
395405
public async logout(): Promise<void> {
396406
return withPassportError<void>(async () => {
397407
await this.userManager.revokeTokens(['refresh_token']);

0 commit comments

Comments
 (0)