Ver código fonte

Towards strict

Manav Rathi 1 ano atrás
pai
commit
acebb86fec

+ 5 - 2
web/apps/auth/src/pages/auth.tsx

@@ -32,8 +32,11 @@ const AuthenticatorCodesPage = () => {
             try {
             try {
                 const res = await getAuthCodes();
                 const res = await getAuthCodes();
                 setCodes(res);
                 setCodes(res);
-            } catch (err) {
-                if (err.message === CustomError.KEY_MISSING) {
+            } catch (e) {
+                if (
+                    e instanceof Error &&
+                    e.message === CustomError.KEY_MISSING
+                ) {
                     InMemoryStore.set(MS_KEYS.REDIRECT_URL, PAGES.AUTH);
                     InMemoryStore.set(MS_KEYS.REDIRECT_URL, PAGES.AUTH);
                     router.push(PAGES.ROOT);
                     router.push(PAGES.ROOT);
                 } else {
                 } else {

+ 4 - 1
web/apps/auth/src/services/remote.ts

@@ -58,7 +58,10 @@ export const getAuthCodes = async (): Promise<Code[]> => {
         });
         });
         return filteredAuthCodes;
         return filteredAuthCodes;
     } catch (e) {
     } catch (e) {
-        if (e.message !== CustomError.AUTH_KEY_NOT_FOUND) {
+        if (
+            e instanceof Error &&
+            e.message !== CustomError.AUTH_KEY_NOT_FOUND
+        ) {
             log.error("get authenticator entities failed", e);
             log.error("get authenticator entities failed", e);
         }
         }
         throw e;
         throw e;

+ 3 - 1
web/apps/auth/tsconfig.json

@@ -12,7 +12,9 @@
 
 
         "jsxImportSource": "@emotion/react",
         "jsxImportSource": "@emotion/react",
 
 
-        "strict": false,
+        "strict": true,
+        "strictNullChecks": false,
+        "noImplicitAny": false,
         /* Stricter than strict */
         /* Stricter than strict */
         "noImplicitReturns": true,
         "noImplicitReturns": true,
         "noUnusedParameters": true,
         "noUnusedParameters": true,

+ 2 - 1
web/packages/accounts/components/SetPasswordForm.tsx

@@ -58,7 +58,8 @@ function SetPasswordForm(props: SetPasswordFormProps) {
                 setFieldError("confirm", t("PASSPHRASE_MATCH_ERROR"));
                 setFieldError("confirm", t("PASSPHRASE_MATCH_ERROR"));
             }
             }
         } catch (e) {
         } catch (e) {
-            setFieldError("confirm", `${t("UNKNOWN_ERROR")} ${e.message}`);
+            const message = e instanceof Error ? e.message : "";
+            setFieldError("confirm", `${t("UNKNOWN_ERROR")} ${message}`);
         } finally {
         } finally {
             setLoading(false);
             setLoading(false);
         }
         }

+ 2 - 1
web/packages/accounts/components/SignUp.tsx

@@ -84,7 +84,8 @@ export default function SignUp({ router, appName, login }: SignUpProps) {
                 setLocalReferralSource(referral);
                 setLocalReferralSource(referral);
                 await sendOtt(appName, email);
                 await sendOtt(appName, email);
             } catch (e) {
             } catch (e) {
-                setFieldError("confirm", `${t("UNKNOWN_ERROR")} ${e.message}`);
+                const message = e instanceof Error ? e.message : "";
+                setFieldError("confirm", `${t("UNKNOWN_ERROR")} ${message}`);
                 throw e;
                 throw e;
             }
             }
             try {
             try {

+ 2 - 1
web/packages/accounts/components/two-factor/VerifyForm.tsx

@@ -47,7 +47,8 @@ export default function VerifyTwoFactor(props: Props) {
             for (let i = 0; i < 6; i++) {
             for (let i = 0; i < 6; i++) {
                 otpInputRef.current?.focusPrevInput();
                 otpInputRef.current?.focusPrevInput();
             }
             }
-            setFieldError("otp", `${t("UNKNOWN_ERROR")} ${e.message}`);
+            const message = e instanceof Error ? e.message : "";
+            setFieldError("otp", `${t("UNKNOWN_ERROR")} ${message}`);
         }
         }
         setWaiting(false);
         setWaiting(false);
     };
     };

+ 4 - 1
web/packages/accounts/pages/credentials.tsx

@@ -197,7 +197,10 @@ export default function Credentials({ appContext, appName }: PageProps) {
                     return keyAttributes;
                     return keyAttributes;
                 }
                 }
             } catch (e) {
             } catch (e) {
-                if (e.message !== CustomError.TWO_FACTOR_ENABLED) {
+                if (
+                    e instanceof Error &&
+                    e.message !== CustomError.TWO_FACTOR_ENABLED
+                ) {
                     log.error("getKeyAttributes failed", e);
                     log.error("getKeyAttributes failed", e);
                 }
                 }
                 throw e;
                 throw e;