Skip to content

Commit 0c239cf

Browse files
authored
Revert "fix(mm-login): Fix 2FA login (#1721)"
This reverts commit 87610a1.
1 parent 2ea5f94 commit 0c239cf

File tree

6 files changed

+48
-88
lines changed

6 files changed

+48
-88
lines changed

src/components/AuthLogin/AuthModal.tsx

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import global from "../ParserOpenRPC/global.module.css";
77
import Icon from "../Icon/Icon";
88
import {
99
authenticateAndAuthorize,
10-
saveTokenString,
11-
getUserIdFromJwtToken,
1210
AUTH_WALLET_PAIRING,
13-
AUTH_WALLET_PROJECTS,
1411
AUTH_WALLET_SESSION_NAME,
15-
AUTH_WALLET_USER_PLAN,
16-
} from "@site/src/lib/siwsrp/auth";
12+
AUTH_WALLET_PROJECTS,
13+
saveTokenString,
14+
getUserIdFromJwtToken,
15+
} from "../../lib/siwsrp/auth";
1716
import {
1817
REQUEST_PARAMS,
18+
AUTH_WALLET_USER_PLAN,
1919
} from "@site/src/lib/constants";
2020
import { MetamaskProviderContext } from "@site/src/theme/Root";
2121

@@ -32,14 +32,16 @@ type AuthModalProps = {
3232

3333
export enum AUTH_LOGIN_STEP {
3434
CONNECTING = "connecting",
35+
WALLET_LOGIN_MULTI_USER = "wallet-login-multi-user",
36+
WALLET_LOGIN_EMAIL_PASSWORD = "wallet-login-email-password",
3537
CONNECTION_ERROR = "connection-error",
3638
CONNECTION_SUCCESS = "connection-success",
3739
}
3840

3941
export enum WALLET_LINK_TYPE {
4042
NO = "NO",
4143
ONE = "ONE",
42-
MULTIPLE = "MULTIPLE"
44+
MULTIPLE = "MULTIPLE",
4345
}
4446

4547
const ConnectingModal = () => {
@@ -148,9 +150,8 @@ const AuthModal = ({
148150
const { DASHBOARD_URL, VERCEL_ENV } = siteConfig?.customFields || {};
149151
const {
150152
sdk,
151-
setNeedsMfa,
152153
setWalletLinked,
153-
setWalletAuthUrl,
154+
setWalletLinkUrl,
154155
metaMaskDisconnect,
155156
setProjects,
156157
setMetaMaskAccount,
@@ -202,22 +203,22 @@ const AuthModal = ({
202203
if (!loginResponse) throw new Error("Something went wrong");
203204

204205
const { data, session, token } = loginResponse;
205-
sessionStorage.setItem(AUTH_WALLET_PAIRING, JSON.stringify({ data }));
206+
localStorage.setItem(AUTH_WALLET_PAIRING, JSON.stringify({ data }));
206207

207208
if (data.step) {
208209
// Handling no wallet pairing or multiple pairing
209210
const mm_auth = Buffer.from(
210211
JSON.stringify({
211212
step: data.step,
212-
mmAuthSession: sessionStorage.getItem(AUTH_WALLET_SESSION_NAME),
213+
mmAuthSession: localStorage.getItem(AUTH_WALLET_SESSION_NAME),
213214
walletPairing: data.pairing,
214215
token: true,
215216
}),
216217
).toString("base64");
217218

218-
const walletAuthUrl = `${DASHBOARD_URL}/login?mm_auth=${mm_auth}&redirect_to=${session.redirect_to}`;
219+
const walletLinkUrl = `${DASHBOARD_URL}/login?mm_auth=${mm_auth}&redirect_to=${session.redirect_to}`;
219220

220-
setWalletAuthUrl(walletAuthUrl);
221+
setWalletLinkUrl(walletLinkUrl);
221222

222223
if (data.pairing && !data.pairing.length) {
223224
setWalletLinked(WALLET_LINK_TYPE.NO);
@@ -232,25 +233,6 @@ const AuthModal = ({
232233
return;
233234
}
234235

235-
if (data.mfa?.enabled) {
236-
const mm_auth = Buffer.from(
237-
JSON.stringify({
238-
step: 'verify',
239-
mmAuthSession: sessionStorage.getItem(AUTH_WALLET_SESSION_NAME),
240-
dashboardSessionToken: token
241-
}),
242-
).toString("base64");
243-
244-
const walletAuthUrl = `${DASHBOARD_URL}/login?mm_auth=${mm_auth}&redirect_to=${session.redirect_to}`;
245-
246-
setWalletAuthUrl(walletAuthUrl);
247-
248-
setNeedsMfa(true);
249-
setStep(AUTH_LOGIN_STEP.CONNECTION_SUCCESS);
250-
setOpen(false);
251-
return;
252-
}
253-
254236
setWalletLinked(WALLET_LINK_TYPE.ONE);
255237

256238
if (!token) {

src/components/Faucet/Hero.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function Hero({
3434
metaMaskWalletIdConnectHandler,
3535
walletLinked,
3636
projects,
37-
walletAuthUrl,
37+
walletLinkUrl,
3838
} = useContext(MetamaskProviderContext);
3939
const isExtensionActive = sdk.isExtensionActive();
4040
const [isWalletLinking, setIsWalletLinking] = useState(false);
@@ -65,7 +65,7 @@ export default function Hero({
6565
responseMsg: null,
6666
timestamp: Date.now(),
6767
});
68-
window.location.href = walletAuthUrl;
68+
window.location.href = walletLinkUrl;
6969
};
7070

7171
const handleRequestEth = () => {

src/components/ParserOpenRPC/ProjectsBox/index.tsx

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ const ProjectsBox = () => {
1313
projects,
1414
metaMaskAccount,
1515
walletLinked,
16-
needsMfa,
1716
metaMaskWalletIdConnectHandler,
18-
walletAuthUrl,
17+
walletLinkUrl,
1918
setUserAPIKey,
2019
} = useContext(MetamaskProviderContext);
2120
const options = Object.keys(projects).map((v) => ({
@@ -115,7 +114,7 @@ const ProjectsBox = () => {
115114
/>
116115
) : (
117116
<div className={styles.selectProjects}>
118-
{!needsMfa && walletLinked === undefined && (
117+
{walletLinked === undefined && (
119118
<>
120119
<div>
121120
{isWalletLinking ?
@@ -133,21 +132,6 @@ const ProjectsBox = () => {
133132
</Button>
134133
</>
135134
)}
136-
{needsMfa && (
137-
<>
138-
<div>
139-
Your Infura account needs two factor auth token
140-
</div>
141-
<Button
142-
thin
143-
variant="secondary"
144-
wrapText={false}
145-
onClick={() => (window.location.href = walletAuthUrl)}
146-
>
147-
Enter your MFA
148-
</Button>
149-
</>
150-
)}
151135
{walletLinked === WALLET_LINK_TYPE.NO && (
152136
<>
153137
<div>
@@ -158,7 +142,7 @@ const ProjectsBox = () => {
158142
thin
159143
variant="secondary"
160144
wrapText={false}
161-
onClick={() => (window.location.href = walletAuthUrl)}
145+
onClick={() => (window.location.href = walletLinkUrl)}
162146
>
163147
Link Infura Account
164148
</Button>
@@ -167,14 +151,14 @@ const ProjectsBox = () => {
167151
{walletLinked === WALLET_LINK_TYPE.MULTIPLE && (
168152
<>
169153
<div>
170-
Select MetaMask Developer account linked with your current wallet.
154+
Select Infura account linked with your current wallet.
171155
</div>
172156
<Button
173157
thin
174158
className={styles.connectButton}
175-
onClick={() => (window.location.href = walletAuthUrl)}
159+
onClick={() => (window.location.href = walletLinkUrl)}
176160
>
177-
Select MetaMask Developer Account
161+
Select Infura Account
178162
</Button>
179163
</>
180164
)}

src/lib/constants.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,4 +469,15 @@ export const REQUEST_PARAMS = (method = "POST", headers = {}) => ({
469469

470470
export const LINEA_PROD_URL = "https://linea-mainnet.infura.io";
471471
export const LINEA_DEV_URL = "https://linea-mainnet.dev.infura.org";
472-
export const LINEA_REQUEST_URL = LINEA_PROD_URL;
472+
export const LINEA_REQUEST_URL = LINEA_PROD_URL;
473+
export const AUTH_WALLET_ENS = "auth.wallet.ens";
474+
export const AUTH_WALLET_PROJECTS = "auth.wallet.projects";
475+
export const AUTH_WALLET_USER_PLAN = "auth.wallet.uksTier";
476+
477+
export const getWalletEns = () => {
478+
return sessionStorage.getItem(AUTH_WALLET_ENS);
479+
};
480+
481+
export const getUksTier = (): string => {
482+
return sessionStorage.getItem(AUTH_WALLET_USER_PLAN);
483+
};

src/lib/siwsrp/auth.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,6 @@ export const AUTH_WALLET_PAIRING = 'auth.wallet.pairing'
1414
export const AUTH_WALLET_SESSION_NAME = 'auth.wallet.session'
1515
export const AUTH_WALLET_TOKEN = 'auth.wallet.token'
1616
export const AUTH_WALLET_PROJECTS = 'auth.wallet.projects'
17-
export const AUTH_WALLET_USER_PLAN = "auth.wallet.uksTier";
18-
export const AUTH_WALLET_ENS = "auth.wallet.ens";
19-
20-
export const getWalletEns = () => {
21-
return sessionStorage.getItem(AUTH_WALLET_ENS);
22-
};
23-
24-
export const getUksTier = (): string => {
25-
return sessionStorage.getItem(AUTH_WALLET_USER_PLAN);
26-
};
27-
2817

2918
const getHydraEnv = (env: string): HydraEnv => {
3019
const platform = Platform.INFURA;
@@ -46,11 +35,11 @@ const getHydraEnv = (env: string): HydraEnv => {
4635

4736
const storage: SDK.AuthStorageOptions = {
4837
getLoginResponse: async () => {
49-
const storedResponse = sessionStorage.getItem(AUTH_WALLET_SESSION_NAME);
38+
const storedResponse = localStorage.getItem(AUTH_WALLET_SESSION_NAME);
5039
return storedResponse ? JSON.parse(storedResponse) : null;
5140
},
5241
setLoginResponse: async (val: SDK.LoginResponse) => {
53-
sessionStorage.setItem(AUTH_WALLET_SESSION_NAME, JSON.stringify(val));
42+
localStorage.setItem(AUTH_WALLET_SESSION_NAME, JSON.stringify(val));
5443
},
5544
};
5645

@@ -99,4 +88,6 @@ export const getUserIdFromJwtToken = () => {
9988

10089
export const clearStorage = () => {
10190
sessionStorage.clear();
91+
localStorage.removeItem(AUTH_WALLET_SESSION_NAME);
92+
localStorage.removeItem(AUTH_WALLET_PAIRING);
10293
};

src/theme/Root.tsx

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ import { MetaMaskSDK, SDKProvider } from "@metamask/sdk";
1212
import {
1313
REF_ALLOW_LOGIN_PATH,
1414
REQUEST_PARAMS,
15+
AUTH_WALLET_PROJECTS,
16+
AUTH_WALLET_ENS,
17+
getWalletEns,
18+
getUksTier,
1519
} from "@site/src/lib/constants";
1620
import {
1721
clearStorage,
1822
getUserIdFromJwtToken,
1923
saveTokenString,
2024
getTokenString,
21-
getUksTier,
22-
AUTH_WALLET_PROJECTS,
23-
AUTH_WALLET_ENS,
24-
getWalletEns
2525
} from "@site/src/lib/siwsrp/auth";
2626
import AuthModal, {
2727
AUTH_LOGIN_STEP,
@@ -56,12 +56,10 @@ interface IMetamaskProviderContext {
5656
setMetaMaskProvider: (arg: SDKProvider) => void;
5757
uksTier: string;
5858
sdk: MetaMaskSDK;
59-
setNeedsMfa: (arg: boolean) => void;
60-
needsMfa: boolean;
6159
setWalletLinked: (arg: WALLET_LINK_TYPE) => void;
6260
walletLinked: WALLET_LINK_TYPE | undefined;
63-
setWalletAuthUrl: (arg: string) => void;
64-
walletAuthUrl: string;
61+
setWalletLinkUrl: (arg: string) => void;
62+
walletLinkUrl: string;
6563
userAPIKey?: string;
6664
setUserAPIKey?: (key: string) => void;
6765
fetchLineaEns?: (walletId: string) => Promise<void>;
@@ -81,12 +79,10 @@ export const MetamaskProviderContext = createContext<IMetamaskProviderContext>({
8179
metaMaskProvider: undefined,
8280
setMetaMaskProvider: () => {},
8381
sdk: undefined,
84-
setNeedsMfa: () => {},
85-
needsMfa: false,
8682
setWalletLinked: () => {},
8783
walletLinked: undefined,
88-
setWalletAuthUrl: () => {},
89-
walletAuthUrl: "",
84+
setWalletLinkUrl: () => {},
85+
walletLinkUrl: "",
9086
userAPIKey: "",
9187
setUserAPIKey: () => {},
9288
fetchLineaEns: () => new Promise(() => {}),
@@ -119,8 +115,7 @@ export const LoginProvider = ({ children }) => {
119115
const [walletLinked, setWalletLinked] = useState<
120116
WALLET_LINK_TYPE | undefined
121117
>(undefined);
122-
const [needsMfa, setNeedsMfa] = useState<boolean>(false);
123-
const [walletAuthUrl, setWalletAuthUrl] = useState<string>("");
118+
const [walletLinkUrl, setWalletLinkUrl] = useState<string>("");
124119
const [userAPIKey, setUserAPIKey] = useState("");
125120
const { siteConfig } = useDocusaurusContext();
126121
const { DASHBOARD_URL, GF_SURVEY_KEY, LINEA_ENS_URL } = siteConfig?.customFields || {};
@@ -190,7 +185,6 @@ export const LoginProvider = ({ children }) => {
190185
setUksTier(undefined);
191186
setProjects({});
192187
setWalletLinked(undefined);
193-
setNeedsMfa(false);
194188
setUserAPIKey("");
195189
clearStorage();
196190
} catch (err) {
@@ -282,10 +276,8 @@ export const LoginProvider = ({ children }) => {
282276
sdk,
283277
walletLinked,
284278
setWalletLinked,
285-
needsMfa,
286-
setNeedsMfa,
287-
walletAuthUrl,
288-
setWalletAuthUrl,
279+
walletLinkUrl,
280+
setWalletLinkUrl,
289281
userAPIKey,
290282
setUserAPIKey,
291283
fetchLineaEns,

0 commit comments

Comments
 (0)