diff --git a/frontend/components/basic/buttons/Button.tsx b/frontend/components/basic/buttons/Button.tsx
index 5fe2db803f..9f8d481b4f 100644
--- a/frontend/components/basic/buttons/Button.tsx
+++ b/frontend/components/basic/buttons/Button.tsx
@@ -12,7 +12,7 @@ type ButtonProps = {
text: string;
onButtonPressed: () => void;
loading?: boolean;
- color: string;
+ color?: string;
size: string;
icon?: IconProp;
active?: boolean;
diff --git a/frontend/components/utilities/SecurityClient.js b/frontend/components/utilities/SecurityClient.js
index f8be6a0e19..78eebdebef 100644
--- a/frontend/components/utilities/SecurityClient.js
+++ b/frontend/components/utilities/SecurityClient.js
@@ -3,7 +3,7 @@ import token from "~/pages/api/auth/Token";
export default class SecurityClient {
static #token = "";
- contructor() {}
+ constructor() {}
static setToken(token) {
this.#token = token;
diff --git a/frontend/components/utilities/attemptLogin.js b/frontend/components/utilities/attemptLogin.js
index 5fe00dc9ae..7f14b20de2 100644
--- a/frontend/components/utilities/attemptLogin.js
+++ b/frontend/components/utilities/attemptLogin.js
@@ -31,7 +31,6 @@ const attemptLogin = async (
isLogin
) => {
try {
- let userWorkspace, userOrg;
const telemetry = new Telemetry().getInstance();
client.init(
@@ -135,20 +134,14 @@ const attemptLogin = async (
// If user is logging in for the first time, add the example keys
if (isSignUp) {
- await pushKeys(
- {
+ await pushKeys({
+ obj: {
DATABASE_URL: [
"mongodb+srv://${DB_USERNAME}:${DB_PASSWORD}@mongodb.net",
"personal",
],
- DB_USERNAME: [
- "user1234",
- "personal",
- ],
- DB_PASSWORD: [
- "ah8jak3hk8dhiu4dw7whxwe1l",
- "personal",
- ],
+ DB_USERNAME: ["user1234", "personal"],
+ DB_PASSWORD: ["ah8jak3hk8dhiu4dw7whxwe1l", "personal"],
TWILIO_AUTH_TOKEN: [
"hgSIwDAKvz8PJfkj6xkzYqzGmAP3HLuG",
"shared",
@@ -156,9 +149,9 @@ const attemptLogin = async (
WEBSITE_URL: ["http://localhost:3000", "shared"],
STRIPE_SECRET_KEY: ["sk_test_7348oyho4hfq398HIUOH78", "shared"],
},
- projectToLogin,
- "Development"
- );
+ workspaceId: projectToLogin,
+ env: "Development"
+ });
}
if (email) {
telemetry.identify(email);
diff --git a/frontend/components/utilities/checks/PasswordCheck.js b/frontend/components/utilities/checks/PasswordCheck.ts
similarity index 83%
rename from frontend/components/utilities/checks/PasswordCheck.js
rename to frontend/components/utilities/checks/PasswordCheck.ts
index 448c2942e4..10240b7476 100644
--- a/frontend/components/utilities/checks/PasswordCheck.js
+++ b/frontend/components/utilities/checks/PasswordCheck.ts
@@ -1,18 +1,21 @@
+interface PasswordCheckProps {
+ password: string;
+ currentErrorCheck: boolean;
+ setPasswordErrorLength: (value: boolean) => void;
+ setPasswordErrorNumber: (value: boolean) => void;
+ setPasswordErrorLowerCase: (value: boolean) => void;
+}
+
/**
* This function checks a user password with respect to some criteria.
- * @param {*} password
- * @param {*} setPasswordError
- * @param {*} setPasswordErrorMessage
- * @param {*} currentErrorCheck
- * @returns
*/
-const passwordCheck = (
+const passwordCheck = ({
password,
setPasswordErrorLength,
setPasswordErrorNumber,
setPasswordErrorLowerCase,
- currentErrorCheck
-) => {
+ currentErrorCheck,
+}: PasswordCheckProps) => {
let errorCheck = currentErrorCheck;
if (!password || password.length < 14) {
setPasswordErrorLength(true);
diff --git a/frontend/components/utilities/checks/tempLocalStorage.ts b/frontend/components/utilities/checks/tempLocalStorage.ts
new file mode 100644
index 0000000000..f24d53aeb3
--- /dev/null
+++ b/frontend/components/utilities/checks/tempLocalStorage.ts
@@ -0,0 +1,11 @@
+// this is temporary util function. create error handling logic for localStorage and delete this.
+export const tempLocalStorage = (key: string) => {
+ const value = localStorage.getItem(key);
+
+ if (value === null || value === "") {
+ console.warn("No value found in localStorage for key");
+ return "";
+ }
+
+ return value;
+};
diff --git a/frontend/pages/_app.js b/frontend/pages/_app.js
index 8bc612b3c0..04d8688992 100644
--- a/frontend/pages/_app.js
+++ b/frontend/pages/_app.js
@@ -2,7 +2,7 @@ import { useEffect } from "react";
import { useRouter } from "next/router";
import { config } from "@fortawesome/fontawesome-svg-core";
-import Layout from "~/components/basic/layout";
+import Layout from "~/components/basic/Layout";
import RouteGuard from "~/components/RouteGuard";
import { publicPaths } from "~/const";
import Telemetry from "~/utilities/telemetry/Telemetry";
diff --git a/frontend/pages/api/organization/GetOrgUserProjects.js b/frontend/pages/api/organization/GetOrgUserProjects.js
index c091934562..c2d751f64d 100644
--- a/frontend/pages/api/organization/GetOrgUserProjects.js
+++ b/frontend/pages/api/organization/GetOrgUserProjects.js
@@ -6,7 +6,7 @@ import SecurityClient from "~/utilities/SecurityClient";
* @param {*} res
* @returns
*/
-const getOrganizationUserProjects = (req, res) => {
+const getOrganizationUserProjects = (req) => {
return SecurityClient.fetchCall(
"/api/v1/organization/" + req.orgId + "/my-workspaces",
{
diff --git a/frontend/pages/api/workspace/getWorkspaces.ts b/frontend/pages/api/workspace/getWorkspaces.ts
index 9427c03d00..33292b6eec 100644
--- a/frontend/pages/api/workspace/getWorkspaces.ts
+++ b/frontend/pages/api/workspace/getWorkspaces.ts
@@ -1,5 +1,13 @@
import SecurityClient from "~/utilities/SecurityClient";
+interface Workspaces {
+ __v: number;
+ _id: string;
+ name: string;
+ organization: string;
+}
+[];
+
/**
* This route lets us get the workspaces of a certain user
* @returns
@@ -12,10 +20,11 @@ const getWorkspaces = () => {
},
}).then(async (res) => {
if (res?.status == 200) {
- return (await res.json()).workspaces;
- } else {
- console.log("Failed to get projects");
+ const data = (await res.json()) as unknown as { workspaces: Workspaces };
+ return data.workspaces;
}
+
+ throw new Error("Failed to get projects");
});
};
diff --git a/frontend/pages/signup.js b/frontend/pages/signup.tsx
similarity index 88%
rename from frontend/pages/signup.js
rename to frontend/pages/signup.tsx
index 77c3c7ef46..cdfb46665c 100644
--- a/frontend/pages/signup.js
+++ b/frontend/pages/signup.tsx
@@ -1,4 +1,5 @@
import React, { useEffect, useRef, useState } from "react";
+import ReactCodeInput from "react-code-input";
import dynamic from "next/dynamic";
import Head from "next/head";
import Image from "next/image";
@@ -20,7 +21,7 @@ import completeAccountInformationSignup from "./api/auth/CompleteAccountInformat
import sendVerificationEmail from "./api/auth/SendVerificationEmail";
import getWorkspaces from "./api/workspace/getWorkspaces";
-const ReactCodeInput = dynamic(import("react-code-input"));
+// const ReactCodeInput = dynamic(import("react-code-input"));
const nacl = require("tweetnacl");
const jsrp = require("jsrp");
nacl.util = require("tweetnacl-util");
@@ -42,7 +43,7 @@ const props = {
border: "1px solid gray",
textAlign: "center",
},
-};
+} as const;
const propsPhone = {
inputStyle: {
fontFamily: "monospace",
@@ -58,7 +59,7 @@ const propsPhone = {
border: "1px solid gray",
textAlign: "center",
},
-};
+} as const;
export default function SignUp() {
const [email, setEmail] = useState("");
@@ -85,15 +86,16 @@ export default function SignUp() {
const [verificationToken, setVerificationToken] = useState();
const [backupKeyIssued, setBackupKeyIssued] = useState(false);
- useEffect(async () => {
- let userWorkspace;
- try {
- const userWorkspaces = await getWorkspaces();
- userWorkspace = userWorkspaces[0]._id;
- router.push("/dashboard/" + userWorkspace);
- } catch (error) {
- console.log("Error - Not logged in yet");
- }
+ useEffect(() => {
+ const tryAuth = async () => {
+ try {
+ const userWorkspaces = await getWorkspaces();
+ router.push("/dashboard/" + userWorkspaces[0]._id);
+ } catch (error) {
+ console.log("Error - Not logged in yet");
+ }
+ };
+ tryAuth();
}, []);
/**
@@ -108,7 +110,7 @@ export default function SignUp() {
} else if (step == 2) {
// Checking if the code matches the email.
const response = await checkEmailVerificationCode(email, code);
- if (response.status == "200" || code == "111222") {
+ if (response.status === 200 || code == "111222") {
setVerificationToken((await response.json()).token);
setStep(3);
} else {
@@ -123,7 +125,7 @@ export default function SignUp() {
* Verifies if the entered email "looks" correct
*/
const emailCheck = () => {
- var emailCheckBool = false;
+ let emailCheckBool = false;
if (!email) {
setEmailError(true);
setEmailErrorMessage("Please enter your email.");
@@ -150,7 +152,7 @@ export default function SignUp() {
// Verifies if the imformation that the users entered (name, workspace) is there, and if the password matched the criteria.
const signupErrorCheck = async () => {
setIsLoading(true);
- var errorCheck = false;
+ let errorCheck = false;
if (!firstName) {
setFirstNameError(true);
errorCheck = true;
@@ -163,13 +165,13 @@ export default function SignUp() {
} else {
setLastNameError(false);
}
- errorCheck = passwordCheck(
+ errorCheck = passwordCheck({
password,
setPasswordErrorLength,
setPasswordErrorNumber,
setPasswordErrorLowerCase,
- errorCheck
- );
+ currentErrorCheck: errorCheck,
+ });
if (!errorCheck) {
// Generate a random pair of a public and a private key
@@ -187,7 +189,8 @@ export default function SignUp() {
32 + (password.slice(0, 32).length - new Blob([password]).size),
"0"
)
- );
+ ) as { ciphertext: string; iv: string; tag: string };
+
localStorage.setItem("PRIVATE_KEY", PRIVATE_KEY);
client.init(
@@ -196,45 +199,47 @@ export default function SignUp() {
password: password,
},
async () => {
- client.createVerifier(async (err, result) => {
- let response = await completeAccountInformationSignup({
- email,
- firstName,
- lastName,
- organizationName: firstName + "'s organization",
- publicKey: PUBLIC_KEY,
- ciphertext,
- iv,
- tag,
- salt: result.salt,
- verifier: result.verifier,
- token: verificationToken,
- });
+ client.createVerifier(
+ async (err: any, result: { salt: string; verifier: string }) => {
+ const response = await completeAccountInformationSignup({
+ email,
+ firstName,
+ lastName,
+ organizationName: firstName + "'s organization",
+ publicKey: PUBLIC_KEY,
+ ciphertext,
+ iv,
+ tag,
+ salt: result.salt,
+ verifier: result.verifier,
+ token: verificationToken,
+ });
- // if everything works, go the main dashboard page.
- if (!errorCheck && response.status == "200") {
- response = await response.json();
+ // if everything works, go the main dashboard page.
+ if (response.status === 200) {
+ // response = await response.json();
- localStorage.setItem("publicKey", PUBLIC_KEY);
- localStorage.setItem("encryptedPrivateKey", ciphertext);
- localStorage.setItem("iv", iv);
- localStorage.setItem("tag", tag);
+ localStorage.setItem("publicKey", PUBLIC_KEY);
+ localStorage.setItem("encryptedPrivateKey", ciphertext);
+ localStorage.setItem("iv", iv);
+ localStorage.setItem("tag", tag);
- try {
- await attemptLogin(
- email,
- password,
- setErrorLogin,
- router,
- true,
- false
- );
- incrementStep();
- } catch (error) {
- setIsLoading(false);
+ try {
+ await attemptLogin(
+ email,
+ password,
+ setErrorLogin,
+ router,
+ true,
+ false
+ );
+ incrementStep();
+ } catch (error) {
+ setIsLoading(false);
+ }
}
}
- });
+ );
}
);
} else {
@@ -296,6 +301,8 @@ export default function SignUp() {
{
+ onChangeHandler={(password: string) => {
setPassword(password);
- passwordCheck(
+ passwordCheck({
password,
setPasswordErrorLength,
setPasswordErrorNumber,
setPasswordErrorLowerCase,
- false
- );
+ currentErrorCheck: false,
+ });
}}
type="password"
value={password}
@@ -496,7 +505,7 @@ export default function SignUp() {
setBackupKeyIssued,
});
const userWorkspaces = await getWorkspaces();
- let userWorkspace = userWorkspaces[0]._id;
+ const userWorkspace = userWorkspaces[0]._id;
router.push("/home/" + userWorkspace);
}}
size="lg"