Skip to content

Commit 7270c72

Browse files
Merge pull request #2133 from Web3Auth/feat/v10-login-modal
sort login methods from auth connection in project config
2 parents dea2b5a + 8134e42 commit 7270c72

File tree

4 files changed

+60
-15
lines changed

4 files changed

+60
-15
lines changed

package-lock.json

Lines changed: 39 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/modal/src/modalManager.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,9 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
6363
super.checkInitRequirements();
6464
// get project config and wallet registry
6565
const { projectConfig, walletRegistry } = await this.getProjectAndWalletConfig();
66-
this.options.uiConfig = deepmerge(cloneDeep(projectConfig.whitelabel || {}), this.options.uiConfig || {});
67-
if (!this.options.uiConfig.defaultLanguage) this.options.uiConfig.defaultLanguage = getUserLanguage(this.options.uiConfig.defaultLanguage);
68-
if (!this.options.uiConfig.mode) this.options.uiConfig.mode = "light";
69-
this.options.uiConfig = deepmerge(projectConfig.loginModal || {}, this.options.uiConfig || {});
7066

7167
// init config
68+
this.initUIConfig(projectConfig);
7269
super.initAccountAbstractionConfig(projectConfig);
7370
super.initChainsConfig(projectConfig);
7471
super.initCachedConnectorAndChainId();
@@ -194,6 +191,25 @@ export class Web3Auth extends Web3AuthNoModal implements IWeb3AuthModal {
194191
return { projectConfig, walletRegistry };
195192
}
196193

194+
private initUIConfig(projectConfig: ProjectConfig) {
195+
this.options.uiConfig = deepmerge(cloneDeep(projectConfig.whitelabel || {}), this.options.uiConfig || {});
196+
if (!this.options.uiConfig.defaultLanguage) this.options.uiConfig.defaultLanguage = getUserLanguage(this.options.uiConfig.defaultLanguage);
197+
if (!this.options.uiConfig.mode) this.options.uiConfig.mode = "light";
198+
this.options.uiConfig = deepmerge(projectConfig.loginModal || {}, this.options.uiConfig);
199+
200+
// merge login methods order from project config and user config, with user config taking precedence
201+
const defaultAuthConnections = projectConfig.embeddedWalletAuth.filter((x) => x.isDefault).map((x) => x.authConnection);
202+
const mergedAuthConnections = [...(this.options.uiConfig.loginMethodsOrder || []), ...defaultAuthConnections];
203+
const loginMethodsOrder = [];
204+
const authConnectionSet = new Set();
205+
for (const authConnection of mergedAuthConnections) {
206+
if (authConnectionSet.has(authConnection)) continue;
207+
authConnectionSet.add(authConnection);
208+
loginMethodsOrder.push(authConnection);
209+
}
210+
this.options.uiConfig.loginMethodsOrder = loginMethodsOrder;
211+
}
212+
197213
private async initConnectors({
198214
connectors,
199215
projectConfig,

packages/modal/src/ui/config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export const restrictedLoginMethods: Set<AUTH_CONNECTION_TYPE> = new Set([
99
AUTH_CONNECTION.PASSKEYS,
1010
AUTH_CONNECTION.TELEGRAM,
1111
AUTH_CONNECTION.AUTHENTICATOR,
12-
AUTH_CONNECTION.WEIBO,
1312
]);
1413
export const AUTH_PROVIDERS = Object.values(AUTH_CONNECTION).filter((x) => !restrictedLoginMethods.has(x));
1514

packages/modal/src/ui/interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface UIConfig extends CoreUIConfig, LoginModalConfig {
3030
/**
3131
* order of how login methods are shown
3232
*
33-
* @defaultValue `["google", "facebook", "twitter", "reddit", "discord", "twitch", "apple", "line", "github", "kakao", "linkedin", "weibo", "wechat", "email_passwordless"]`
33+
* @defaultValue `["google", "facebook", "twitter", "reddit", "discord", "twitch", "apple", "line", "github", "kakao", "linkedin", "wechat", "email_passwordless"]`
3434
*/
3535
loginMethodsOrder?: string[];
3636

0 commit comments

Comments
 (0)