Skip to content
Closed
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
4 changes: 2 additions & 2 deletions packages/game-bridge/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ window.callFunction = async (jsonData: string) => {
}
case PASSPORT_FUNCTIONS.getPKCEAuthUrl: {
const request = data ? JSON.parse(data) : {};
const directLoginMethod = request?.directLoginMethod;
const url = await getPassportClient().loginWithPKCEFlow(directLoginMethod);
const directLoginOptions: passport.DirectLoginOptions | undefined = request?.directLoginOptions;
const url = await getPassportClient().loginWithPKCEFlow(directLoginOptions);
trackDuration(moduleName, 'performedGetPkceAuthUrl', mt(markStart));
callbackToGame({
responseFor: fxName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export function PassportProvider({
const popupRedirectGoogle = useCallback(async () => {
try {
setIsLoading(true);
const userProfile = await passportClient.login({ directLoginMethod: 'google' });
const userProfile = await passportClient.login({ directLoginOptions: { method: 'google' } });
addMessage('Popup Login (Google)', userProfile);
} catch (err) {
addMessage('Popup Login (Google)', err);
Expand All @@ -192,7 +192,7 @@ export function PassportProvider({
const popupRedirectApple = useCallback(async () => {
try {
setIsLoading(true);
const userProfile = await passportClient.login({ directLoginMethod: 'apple' });
const userProfile = await passportClient.login({ directLoginOptions: { method: 'apple' } });
addMessage('Popup Login (Apple)', userProfile);
} catch (err) {
addMessage('Popup Login (Apple)', err);
Expand All @@ -205,7 +205,7 @@ export function PassportProvider({
const popupRedirectFacebook = useCallback(async () => {
try {
setIsLoading(true);
const userProfile = await passportClient.login({ directLoginMethod: 'facebook' });
const userProfile = await passportClient.login({ directLoginOptions: { method: 'facebook' } });
addMessage('Popup Login (Facebook)', userProfile);
} catch (err) {
addMessage('Popup Login (Facebook)', err);
Expand All @@ -220,7 +220,7 @@ export function PassportProvider({
try {
setIsLoading(true);
const userProfile = await passportClient.login({
directLoginMethod: 'google',
directLoginOptions: { method: 'google' },
useRedirectFlow: true,
});
addMessage('Login (Google)', userProfile);
Expand All @@ -236,7 +236,7 @@ export function PassportProvider({
try {
setIsLoading(true);
const userProfile = await passportClient.login({
directLoginMethod: 'apple',
directLoginOptions: { method: 'apple' },
useRedirectFlow: true,
});
addMessage('Login (Apple)', userProfile);
Expand All @@ -252,7 +252,7 @@ export function PassportProvider({
try {
setIsLoading(true);
const userProfile = await passportClient.login({
directLoginMethod: 'facebook',
directLoginOptions: { method: 'facebook' },
useRedirectFlow: true,
});
addMessage('Login (Facebook)', userProfile);
Expand Down
16 changes: 8 additions & 8 deletions packages/passport/sdk/src/Passport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { PassportImxProviderFactory } from './starkEx';
import { PassportConfiguration } from './config';
import {
DeviceTokenResponse,
DirectLoginMethod,
DirectLoginOptions,
isUserImx,
isUserZkEvm,
LinkedWallet,
Expand Down Expand Up @@ -192,7 +192,7 @@ export class Passport {
* @param {boolean} [options.useSilentLogin] - If true, attempts silent authentication without user interaction.
* Note: This takes precedence over useCachedSession if both are true
* @param {boolean} [options.useRedirectFlow] - If true, uses redirect flow instead of popup flow
* @param {DirectLoginMethod} [options.directLoginMethod] - If provided, directly redirects to the specified login method
* @param {DirectLoginOptions} [options.directLoginOptions] - Type-safe login options. For email login, use { method: 'email', email: 'user@example.com' }. For social login, use { method: 'google' } etc.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't comment on the options being type-safe, it makes the comment seem like it was written by an LLM 😉

* @returns {Promise<UserProfile | null>} A promise that resolves to the user profile if logged in, null otherwise
* @throws {Error} If retrieving the cached user session fails (except for "Unknown or invalid refresh token" errors)
* and useCachedSession is true
Expand All @@ -202,7 +202,7 @@ export class Passport {
anonymousId?: string;
useSilentLogin?: boolean;
useRedirectFlow?: boolean;
directLoginMethod?: DirectLoginMethod;
directLoginOptions?: DirectLoginOptions;
}): Promise<UserProfile | null> {
// If there's already a login in progress, return that promise
if (this.#loginPromise) {
Expand Down Expand Up @@ -230,9 +230,9 @@ export class Passport {
user = await this.authManager.forceUserRefresh();
} else if (!user && !useCachedSession) {
if (options?.useRedirectFlow) {
await this.authManager.loginWithRedirect(options?.anonymousId, options?.directLoginMethod);
await this.authManager.loginWithRedirect(options?.anonymousId, options?.directLoginOptions);
} else {
user = await this.authManager.login(options?.anonymousId, options?.directLoginMethod);
user = await this.authManager.login(options?.anonymousId, options?.directLoginOptions);
}
}

Expand Down Expand Up @@ -273,11 +273,11 @@ export class Passport {

/**
* Initiates a PKCE flow login.
* @param {DirectLoginMethod} [directLoginMethod] - If provided, directly redirects to the specified login method
* @param {DirectLoginOptions} [directLoginOptions] - Type-safe login options. For email login, use { method: 'email', email: 'user@example.com' }. For social login, use { method: 'google' } etc.
* @returns {string} The authorization URL for the PKCE flow
*/
public loginWithPKCEFlow(directLoginMethod?: DirectLoginMethod): Promise<string> {
return withMetricsAsync(async () => await this.authManager.getPKCEAuthorizationUrl(directLoginMethod), 'loginWithPKCEFlow');
public loginWithPKCEFlow(directLoginOptions?: DirectLoginOptions): Promise<string> {
return withMetricsAsync(async () => await this.authManager.getPKCEAuthorizationUrl(directLoginOptions), 'loginWithPKCEFlow');
}

/**
Expand Down
Loading
Loading