Skip to content

Commit 521b999

Browse files
Merge pull request #2145 from Web3Auth/feat/email-passwordless-captcha
Adds Email Passwordless Captcha
2 parents 8e5c8f9 + 551a04f commit 521b999

File tree

9 files changed

+49
-14
lines changed

9 files changed

+49
-14
lines changed

package-lock.json

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

packages/modal/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"@coinbase/wallet-sdk": "^4.3.x",
5252
"@mertasan/tailwindcss-variables": "^2.7.0",
5353
"@rollup/plugin-json": "^6.1.0",
54+
"@rollup/plugin-replace": "^6.0.2",
5455
"@rollup/plugin-url": "^8.0.2",
5556
"@svgr/rollup": "^8.1.0",
5657
"@svgr/webpack": "^8.1.0",

packages/modal/rollup.config.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
/* eslint-disable import/no-extraneous-dependencies */
22
import json from "@rollup/plugin-json";
3+
import replace from "@rollup/plugin-replace";
34
import url from "@rollup/plugin-url";
45
import svgr from "@svgr/rollup";
6+
import { readJSONFile } from "@toruslabs/torus-scripts/helpers/utils.js";
57
import path from "path";
68
import postcss from "rollup-plugin-postcss";
9+
10+
const pkg = await readJSONFile(path.resolve("./package.json"));
711
// TODO: use ssr module for cjs build
812

913
export const baseConfig = {
1014
input: ["./src/index.ts", "./src/react/index.ts", "./src/vue/index.ts"],
1115
plugins: [
16+
replace({
17+
"process.env.WEB3AUTH_VERSION": `"${pkg.version}"`,
18+
preventAssignment: true,
19+
}),
1220
postcss({
1321
config: {
1422
path: path.resolve("./postcss.config.js"),

packages/modal/src/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { EVM_CONNECTORS } from "@web3auth/no-modal";
22

33
import { ConnectorsModalConfig } from "./interface";
44

5+
export const version = process.env.WEB3AUTH_VERSION;
6+
57
export const defaultConnectorsModalConfig: ConnectorsModalConfig = {
68
hideWalletDiscovery: false,
79
connectors: {

packages/modal/src/ui/components/Login/Login.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,11 @@ function Login(props: LoginProps) {
186186
authBuildEnv,
187187
});
188188

189-
let token = "";
190-
if (authConnection === AUTH_CONNECTION.SMS_PASSWORDLESS) {
191-
const res = await captchaRef.current?.execute({ async: true });
192-
if (!res) {
193-
throw WalletLoginError.connectionError("Captcha token is required");
194-
}
195-
token = res.response;
189+
const res = await captchaRef.current?.execute({ async: true });
190+
if (!res) {
191+
throw WalletLoginError.connectionError("Captcha token is required");
196192
}
193+
const token = res.response;
197194

198195
const result = await handler.sendVerificationCode({ captchaToken: token });
199196
if (result?.error) {

packages/modal/src/ui/handlers/AbstractHandler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { post } from "@toruslabs/http-helpers";
22
import { AUTH_CONNECTION, BUILD_ENV, storageAvailable } from "@web3auth/auth";
33
import { WalletInitializationError } from "@web3auth/no-modal";
44

5+
import { version } from "../../config";
56
import { PASSWORDLESS_BUILD_ENV_MAP } from "../config";
67
import {
78
CodeInitiateRequestBodyParams,
@@ -20,6 +21,8 @@ export abstract class PasswordlessHandler {
2021

2122
trackingIdentifier?: string;
2223

24+
version: string = `web3auth-${version.split(".")[0]}`;
25+
2326
constructor(params: PasswordlessHandlerParams) {
2427
if (!params.authConnection) throw WalletInitializationError.invalidParams("authConnection is required");
2528
if (!params.web3authClientId) throw WalletInitializationError.invalidParams("web3authClientId is required");
@@ -120,7 +123,7 @@ export abstract class PasswordlessHandler {
120123
};
121124
}
122125

123-
abstract sendVerificationCode(params?: { captchaToken: string }): Promise<IStartResponse>;
126+
abstract sendVerificationCode(params: { captchaToken: string }): Promise<IStartResponse>;
124127

125128
abstract verifyCode(code: string): Promise<IVerifyResponse>;
126129
}

packages/modal/src/ui/handlers/EmailPasswordlessHandler.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default class EmailPasswordlessHandler extends PasswordlessHandler {
1414
if (this.sessionStorageAvailable) this.trackingId = window.sessionStorage.getItem("trackingId") ?? undefined;
1515
}
1616

17-
async sendVerificationCode() {
17+
async sendVerificationCode({ captchaToken }: { captchaToken?: string }) {
1818
const { loginHint, network, web3authClientId } = this.passwordlessParams;
1919

2020
const finalParams: CodeInitiateRequestBodyParams = {
@@ -24,9 +24,10 @@ export default class EmailPasswordlessHandler extends PasswordlessHandler {
2424
login_hint: loginHint,
2525
tracking_id: this.trackingId,
2626
whitelabel: this.whiteLabelParams,
27-
version: "",
27+
version: this.version,
2828
network,
2929
flow_type: EMAIL_FLOW.code,
30+
captcha_token: captchaToken,
3031
};
3132

3233
return super.start(finalParams);
@@ -41,7 +42,7 @@ export default class EmailPasswordlessHandler extends PasswordlessHandler {
4142
code,
4243
connection: "email",
4344
tracking_id: this.trackingId as string,
44-
version: "",
45+
version: this.version,
4546
network,
4647
flow_type: EMAIL_FLOW.code,
4748
};

packages/modal/src/ui/handlers/SmsPasswordlessHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default class SmsPasswordlessHandler extends PasswordlessHandler {
2828
login_hint: loginHint,
2929
tracking_id: this.trackingId,
3030
whitelabel: this.whiteLabelParams,
31-
version: "",
31+
version: this.version,
3232
network,
3333
captcha_token: captchaToken,
3434
};
@@ -44,7 +44,7 @@ export default class SmsPasswordlessHandler extends PasswordlessHandler {
4444
code,
4545
connection: this.connection,
4646
tracking_id: this.trackingId as string,
47-
version: "",
47+
version: this.version,
4848
network,
4949
};
5050
return super.verify(params);

packages/modal/webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* eslint-disable @typescript-eslint/no-var-requires */
21
const path = require("path");
2+
const { EnvironmentPlugin } = require("webpack");
33
const generateWebpackConfig = require("../../webpack.config");
44

55
const pkg = require("./package.json");
@@ -67,6 +67,7 @@ const config = generateWebpackConfig({
6767
},
6868
],
6969
},
70+
plugins: [new EnvironmentPlugin({ WEB3AUTH_VERSION: pkg.version })],
7071
ssrModule,
7172
});
7273

0 commit comments

Comments
 (0)