{orgs
.filter(
- (org) => org._id != localStorage.getItem("orgData.id")
+ (org : { _id: string }) => org._id != localStorage.getItem("orgData.id")
)
- .map((org) => (
+ .map((org : { _id: string; name: string; }) => (
{
diff --git a/frontend/components/navigation/NavHeader.js b/frontend/components/navigation/NavHeader.tsx
similarity index 67%
rename from frontend/components/navigation/NavHeader.js
rename to frontend/components/navigation/NavHeader.tsx
index 3f65a5aa62..3d64c2edab 100644
--- a/frontend/components/navigation/NavHeader.js
+++ b/frontend/components/navigation/NavHeader.tsx
@@ -1,29 +1,37 @@
import React, { useEffect, useState } from "react";
import { useRouter } from "next/router";
-import { faCcMastercard, faCcVisa } from "@fortawesome/free-brands-svg-icons";
import {
faAngleRight,
- faQuestionCircle,
} from "@fortawesome/free-solid-svg-icons";
-import { faCircle } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import getOrganization from "~/pages/api/organization/GetOrg";
-import getWorkspaceInfo from "~/pages/api/workspace/getWorkspaceInfo";
+import getProjectInfo from "~/pages/api/workspace/getProjectInfo";
-export default function NavHeader({ pageName, isProjectRelated }) {
+/**
+ * This is the component at the top of almost every page.
+ * It shows how to navigate to a certain page.
+ * It future these links should also be clickable and hoverable
+ * @param obj
+ * @param obj.pageName - Name of the page
+ * @param obj.isProjectRelated - whether this page is related to project or now (determine if it's 2 or 3 navigation steps)
+ * @returns
+ */
+export default function NavHeader({ pageName, isProjectRelated } : { pageName: string; isProjectRelated: boolean; }): JSX.Element {
const [orgName, setOrgName] = useState("");
const [workspaceName, setWorkspaceName] = useState("");
const router = useRouter();
useEffect(() => {
(async () => {
- let org = await getOrganization({
- orgId: localStorage.getItem("orgData.id"),
+ const orgId = localStorage.getItem("orgData.id")
+ const org = await getOrganization({
+ orgId: orgId ? orgId : "",
});
setOrgName(org.name);
- let workspace = await getWorkspaceInfo({
- workspaceId: router.query.id,
+
+ const workspace = await getProjectInfo({
+ projectId: String(router.query.id),
});
setWorkspaceName(workspace.name);
})();
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 c2e6bfc4b5..45cee1f945 100644
--- a/frontend/components/utilities/attemptLogin.js
+++ b/frontend/components/utilities/attemptLogin.js
@@ -32,7 +32,6 @@ const attemptLogin = async (
isLogin
) => {
try {
- let userWorkspace, userOrg;
client.init(
{
username: email,
@@ -43,7 +42,7 @@ const attemptLogin = async (
let serverPublicKey, salt;
try {
- const res = await login1(email, clientPublicKey);
+ let res = await login1(email, clientPublicKey);
res = await res.json();
serverPublicKey = res.serverPublicKey;
salt = res.salt;
@@ -134,20 +133,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",
@@ -155,9 +148,9 @@ const attemptLogin = async (
WEBSITE_URL: ["http://localhost:3000", "shared"],
STRIPE_SECRET_KEY: ["sk_test_7348oyho4hfq398HIUOH78", "shared"],
},
- projectToLogin,
- "Development"
- );
+ workspaceId: projectToLogin,
+ env: "Development"
+ });
}
try {
if (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/components/utilities/cryptography/changePassword.js b/frontend/components/utilities/cryptography/changePassword.js
index 8bfaad6746..de0fd9c3a7 100644
--- a/frontend/components/utilities/cryptography/changePassword.js
+++ b/frontend/components/utilities/cryptography/changePassword.js
@@ -108,11 +108,7 @@ const changePassword = async (
}
);
} catch (error) {
- console.log(
- "Something went wrong during changing the password",
- slat,
- serverPublicKey
- );
+ console.log("Something went wrong during changing the password");
}
return true;
};
diff --git a/frontend/components/utilities/secrets/pushKeys.js b/frontend/components/utilities/secrets/pushKeys.ts
similarity index 69%
rename from frontend/components/utilities/secrets/pushKeys.js
rename to frontend/components/utilities/secrets/pushKeys.ts
index fde5b45a42..0d570f2738 100644
--- a/frontend/components/utilities/secrets/pushKeys.js
+++ b/frontend/components/utilities/secrets/pushKeys.ts
@@ -7,20 +7,30 @@ import { envMapping } from "../../../public/data/frequentConstants";
const crypto = require("crypto");
const {
decryptAssymmetric,
- decryptSymmetric,
encryptSymmetric,
encryptAssymmetric,
} = require("../cryptography/crypto");
const nacl = require("tweetnacl");
nacl.util = require("tweetnacl-util");
+export interface IK {
+ publicKey: string;
+ userId: string;
+}
-const pushKeys = async (obj, workspaceId, env) => {
- let sharedKey = await getLatestFileKey(workspaceId);
+/**
+ * This function pushes the keys to the database after decrypting them end-to-end
+ * @param {object} obj
+ * @param {object} obj.obj - object with all the key pairs
+ * @param {object} obj.workspaceId - the id of a project to which a user is pushing
+ * @param {object} obj.env - which environment a user is pushing to
+ */
+const pushKeys = async({ obj, workspaceId, env }: { obj: object; workspaceId: string; env: string; }) => {
+ const sharedKey = await getLatestFileKey({ workspaceId });
const PRIVATE_KEY = localStorage.getItem("PRIVATE_KEY");
- let randomBytes;
+ let randomBytes: string;
if (Object.keys(sharedKey).length > 0) {
// case: a (shared) key exists for the workspace
randomBytes = decryptAssymmetric({
@@ -51,11 +61,11 @@ const pushKeys = async (obj, workspaceId, env) => {
iv: ivValue,
tag: tagValue,
} = encryptSymmetric({
- plaintext: obj[key][0],
+ plaintext: obj[key as keyof typeof obj][0],
key: randomBytes,
});
- const visibility = obj[key][1] != null ? obj[key][1] : "personal";
+ const visibility = obj[key as keyof typeof obj][1] != null ? obj[key as keyof typeof obj][1] : "personal";
return {
ciphertextKey,
@@ -65,7 +75,7 @@ const pushKeys = async (obj, workspaceId, env) => {
ciphertextValue,
ivValue,
tagValue,
- hashValue: crypto.createHash("sha256").update(obj[key][0]).digest("hex"),
+ hashValue: crypto.createHash("sha256").update(obj[key as keyof typeof obj][0]).digest("hex"),
type: visibility,
};
});
@@ -76,7 +86,7 @@ const pushKeys = async (obj, workspaceId, env) => {
});
// assymmetrically encrypt key with each receiver public keys
- const keys = publicKeys.map((k) => {
+ const keys = publicKeys.map((k: IK) => {
const { ciphertext, nonce } = encryptAssymmetric({
plaintext: randomBytes,
publicKey: k.publicKey,
@@ -95,7 +105,7 @@ const pushKeys = async (obj, workspaceId, env) => {
workspaceId,
secrets,
keys,
- environment: envMapping[env],
+ environment: envMapping[env as keyof typeof envMapping],
});
};
diff --git a/frontend/pages/api/auth/IssueBackupPrivateKey.js b/frontend/pages/api/auth/IssueBackupPrivateKey.js
index 43e9f64eef..9a31f7b008 100644
--- a/frontend/pages/api/auth/IssueBackupPrivateKey.js
+++ b/frontend/pages/api/auth/IssueBackupPrivateKey.js
@@ -31,8 +31,8 @@ const issueBackupPrivateKey = ({
if (res.status == 200) {
return res;
} else {
- return res;
console.log("Failed to issue the backup key");
+ return res;
}
});
};
diff --git a/frontend/pages/api/auth/Logout.js b/frontend/pages/api/auth/Logout.ts
similarity index 89%
rename from frontend/pages/api/auth/Logout.js
rename to frontend/pages/api/auth/Logout.ts
index 24c338a275..4dbcb7bcaa 100644
--- a/frontend/pages/api/auth/Logout.js
+++ b/frontend/pages/api/auth/Logout.ts
@@ -3,11 +3,8 @@ import SecurityClient from "~/utilities/SecurityClient";
/**
* This route logs the user out. Note: the user should authorized to do this.
* We first try to log out - if the authorization fails (response.status = 401), we refetch the new token, and then retry
- * @param {*} req
- * @param {*} res
- * @returns
*/
-const logout = async (req, res) => {
+const logout = async () => {
return SecurityClient.fetchCall("/api/v1/auth/logout", {
method: "POST",
headers: {
@@ -15,7 +12,7 @@ const logout = async (req, res) => {
},
credentials: "include",
}).then((res) => {
- if (res.status == 200) {
+ if (res?.status == 200) {
SecurityClient.setToken("");
// Delete the cookie by not setting a value; Alternatively clear the local storage
localStorage.setItem("publicKey", "");
diff --git a/frontend/pages/api/organization/GetOrg.js b/frontend/pages/api/organization/GetOrg.ts
similarity index 65%
rename from frontend/pages/api/organization/GetOrg.js
rename to frontend/pages/api/organization/GetOrg.ts
index 74782a564f..ecb07bd2d3 100644
--- a/frontend/pages/api/organization/GetOrg.js
+++ b/frontend/pages/api/organization/GetOrg.ts
@@ -2,18 +2,17 @@ import SecurityClient from "~/utilities/SecurityClient";
/**
* This route lets us get info about a certain org
- * @param {*} req
- * @param {*} res
+ * @param {string} orgId - the organization ID
* @returns
*/
-const getOrganization = (req, res) => {
- return SecurityClient.fetchCall("/api/v1/organization/" + req.orgId, {
+const getOrganization = ({ orgId }: { orgId: string; }) => {
+ return SecurityClient.fetchCall("/api/v1/organization/" + orgId, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
}).then(async (res) => {
- if (res.status == 200) {
+ if (res?.status == 200) {
return (await res.json()).organization;
} else {
console.log("Failed to get org info");
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/organization/GetOrgUsers.js b/frontend/pages/api/organization/GetOrgUsers.ts
similarity index 85%
rename from frontend/pages/api/organization/GetOrgUsers.js
rename to frontend/pages/api/organization/GetOrgUsers.ts
index 81e9caa4da..53b9518cf8 100644
--- a/frontend/pages/api/organization/GetOrgUsers.js
+++ b/frontend/pages/api/organization/GetOrgUsers.ts
@@ -6,7 +6,7 @@ import SecurityClient from "~/utilities/SecurityClient";
* @param {string} obj.orgId - organization Id
* @returns
*/
-const getOrganizationUsers = ({ orgId }) => {
+const getOrganizationUsers = ({ orgId }: { orgId: string; }) => {
return SecurityClient.fetchCall(
"/api/v1/organization/" + orgId + "/users",
{
@@ -16,7 +16,7 @@ const getOrganizationUsers = ({ orgId }) => {
},
}
).then(async (res) => {
- if (res.status == 200) {
+ if (res?.status == 200) {
return (await res.json()).users;
} else {
console.log("Failed to get org users");
diff --git a/frontend/pages/api/organization/getOrgs.js b/frontend/pages/api/organization/getOrgs.ts
similarity index 81%
rename from frontend/pages/api/organization/getOrgs.js
rename to frontend/pages/api/organization/getOrgs.ts
index 6720c22a9d..cc655642ff 100644
--- a/frontend/pages/api/organization/getOrgs.js
+++ b/frontend/pages/api/organization/getOrgs.ts
@@ -2,18 +2,16 @@ import SecurityClient from "~/utilities/SecurityClient";
/**
* This route lets us get the all the orgs of a certain user.
- * @param {*} req
- * @param {*} res
* @returns
*/
-const getOrganizations = (req, res) => {
+const getOrganizations = () => {
return SecurityClient.fetchCall("/api/v1/organization", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
}).then(async (res) => {
- if (res.status == 200) {
+ if (res?.status == 200) {
return (await res.json()).organizations;
} else {
console.log("Failed to get orgs of a user");
diff --git a/frontend/pages/api/user/getUser.js b/frontend/pages/api/user/getUser.ts
similarity index 79%
rename from frontend/pages/api/user/getUser.js
rename to frontend/pages/api/user/getUser.ts
index 10ca0d5f80..4bfebc5fe4 100644
--- a/frontend/pages/api/user/getUser.js
+++ b/frontend/pages/api/user/getUser.ts
@@ -2,18 +2,15 @@ import SecurityClient from "~/utilities/SecurityClient";
/**
* This route gets the information about a specific user.
- * @param {*} req
- * @param {*} res
- * @returns
*/
-const getUser = (req, res) => {
+const getUser = () => {
return SecurityClient.fetchCall("/api/v1/user", {
method: "GET",
headers: {
"Content-Type": "application/json",
},
}).then(async (res) => {
- if (res.status == 200) {
+ if (res?.status == 200) {
return (await res.json()).user;
} else {
console.log("Failed to get user info");
diff --git a/frontend/pages/api/workspace/createWorkspace.js b/frontend/pages/api/workspace/createWorkspace.ts
similarity index 61%
rename from frontend/pages/api/workspace/createWorkspace.js
rename to frontend/pages/api/workspace/createWorkspace.ts
index d5c44e2a6e..0cedb0a57d 100644
--- a/frontend/pages/api/workspace/createWorkspace.js
+++ b/frontend/pages/api/workspace/createWorkspace.ts
@@ -1,11 +1,12 @@
import SecurityClient from "~/utilities/SecurityClient";
/**
- * This route creates a new workspace for a user.
- * @param {*} workspaceName
+ * This route creates a new workspace for a user within a certain organization.
+ * @param {string} workspaceName - project Name
+ * @param {string} organizationId - org ID
* @returns
*/
-const createWorkspace = (workspaceName, organizationId) => {
+const createWorkspace = ( { workspaceName, organizationId }: { workspaceName: string; organizationId: string; }) => {
return SecurityClient.fetchCall("/api/v1/workspace", {
method: "POST",
headers: {
@@ -16,7 +17,7 @@ const createWorkspace = (workspaceName, organizationId) => {
organizationId: organizationId,
}),
}).then(async (res) => {
- if (res.status == 200) {
+ if (res?.status == 200) {
return (await res.json()).workspace;
} else {
console.log("Failed to create a project");
diff --git a/frontend/pages/api/workspace/getLatestFileKey.js b/frontend/pages/api/workspace/getLatestFileKey.ts
similarity index 79%
rename from frontend/pages/api/workspace/getLatestFileKey.js
rename to frontend/pages/api/workspace/getLatestFileKey.ts
index a5b14520a6..86ecb74565 100644
--- a/frontend/pages/api/workspace/getLatestFileKey.js
+++ b/frontend/pages/api/workspace/getLatestFileKey.ts
@@ -2,10 +2,10 @@ import SecurityClient from "~/utilities/SecurityClient";
/**
* Get the latest key pairs from a certain workspace
- * @param {*} workspaceId
+ * @param {string} workspaceId
* @returns
*/
-const getLatestFileKey = (workspaceId) => {
+const getLatestFileKey = ({ workspaceId } : { workspaceId: string; }) => {
return SecurityClient.fetchCall(
"/api/v1/key/" + workspaceId + "/latest",
{
@@ -15,7 +15,7 @@ const getLatestFileKey = (workspaceId) => {
},
}
).then(async (res) => {
- if (res.status == 200) {
+ if (res?.status == 200) {
return await res.json();
} else {
console.log("Failed to get the latest key pairs for a certain project");
diff --git a/frontend/pages/api/workspace/getWorkspaceInfo.js b/frontend/pages/api/workspace/getProjectInfo.ts
similarity index 62%
rename from frontend/pages/api/workspace/getWorkspaceInfo.js
rename to frontend/pages/api/workspace/getProjectInfo.ts
index 4266dbbaaf..c6eef9dcea 100644
--- a/frontend/pages/api/workspace/getWorkspaceInfo.js
+++ b/frontend/pages/api/workspace/getProjectInfo.ts
@@ -2,13 +2,12 @@ import SecurityClient from "~/utilities/SecurityClient";
/**
* This route lets us get the information of a certain project.
- * @param {*} req
- * @param {*} res
+ * @param {*} projectId - project ID (we renamed workspaces to projects in the app)
* @returns
*/
-const getWorkspaceInfo = (req, res) => {
+const getProjectInfo = ({ projectId }: { projectId: string; }) => {
return SecurityClient.fetchCall(
- "/api/v1/workspace/" + req.workspaceId,
+ "/api/v1/workspace/" + projectId,
{
method: "GET",
headers: {
@@ -16,7 +15,7 @@ const getWorkspaceInfo = (req, res) => {
},
}
).then(async (res) => {
- if (res.status == 200) {
+ if (res?.status == 200) {
return (await res.json()).workspace;
} else {
console.log("Failed to get project info");
@@ -24,4 +23,4 @@ const getWorkspaceInfo = (req, res) => {
});
};
-export default getWorkspaceInfo;
+export default getProjectInfo;
diff --git a/frontend/pages/api/workspace/getWorkspaceKeys.js b/frontend/pages/api/workspace/getWorkspaceKeys.ts
similarity index 73%
rename from frontend/pages/api/workspace/getWorkspaceKeys.js
rename to frontend/pages/api/workspace/getWorkspaceKeys.ts
index 368d00fa06..09b4686622 100644
--- a/frontend/pages/api/workspace/getWorkspaceKeys.js
+++ b/frontend/pages/api/workspace/getWorkspaceKeys.ts
@@ -2,13 +2,12 @@ import SecurityClient from "~/utilities/SecurityClient";
/**
* This route lets us get the public keys of everyone in your workspace.
- * @param {*} req
- * @param {*} res
+ * @param {string} workspaceId
* @returns
*/
-const getWorkspaceKeys = (req, res) => {
+const getWorkspaceKeys = ({ workspaceId }: { workspaceId: string; }) => {
return SecurityClient.fetchCall(
- "/api/v1/workspace/" + req.workspaceId + "/keys",
+ "/api/v1/workspace/" + workspaceId + "/keys",
{
method: "GET",
headers: {
@@ -16,7 +15,7 @@ const getWorkspaceKeys = (req, res) => {
},
}
).then(async (res) => {
- if (res.status == 200) {
+ if (res?.status == 200) {
return (await res.json()).publicKeys;
} else {
console.log("Failed to get the public keys of everyone in the workspace");
diff --git a/frontend/pages/api/workspace/getWorkspaceUsers.js b/frontend/pages/api/workspace/getWorkspaceUsers.ts
similarity index 69%
rename from frontend/pages/api/workspace/getWorkspaceUsers.js
rename to frontend/pages/api/workspace/getWorkspaceUsers.ts
index 4d87836c7e..9805c26955 100644
--- a/frontend/pages/api/workspace/getWorkspaceUsers.js
+++ b/frontend/pages/api/workspace/getWorkspaceUsers.ts
@@ -2,13 +2,12 @@ import SecurityClient from "~/utilities/SecurityClient";
/**
* This route lets us get all the users in the workspace.
- * @param {*} req
- * @param {*} res
+ * @param {string} workspaceId - workspace ID
* @returns
*/
-const getWorkspaceUsers = (req, res) => {
+const getWorkspaceUsers = ({ workspaceId }: { workspaceId: string; }) => {
return SecurityClient.fetchCall(
- "/api/v1/workspace/" + req.workspaceId + "/users",
+ "/api/v1/workspace/" + workspaceId + "/users",
{
method: "GET",
headers: {
@@ -16,7 +15,7 @@ const getWorkspaceUsers = (req, res) => {
},
}
).then(async (res) => {
- if (res.status == 200) {
+ if (res?.status == 200) {
return (await res.json()).users;
} else {
console.log("Failed to get Project Users");
diff --git a/frontend/pages/api/workspace/getWorkspaces.js b/frontend/pages/api/workspace/getWorkspaces.js
deleted file mode 100644
index ccaf49e9b1..0000000000
--- a/frontend/pages/api/workspace/getWorkspaces.js
+++ /dev/null
@@ -1,24 +0,0 @@
-import SecurityClient from "~/utilities/SecurityClient";
-
-/**
- * This route lets us get the public keys of everyone in your workspace.
- * @param {*} req
- * @param {*} res
- * @returns
- */
-const getWorkspaces = (req, res) => {
- return SecurityClient.fetchCall("/api/v1/workspace", {
- method: "GET",
- headers: {
- "Content-Type": "application/json",
- },
- }).then(async (res) => {
- if (res.status == 200) {
- return (await res.json()).workspaces;
- } else {
- console.log("Failed to get projects");
- }
- });
-};
-
-export default getWorkspaces;
diff --git a/frontend/pages/api/workspace/getWorkspaces.ts b/frontend/pages/api/workspace/getWorkspaces.ts
new file mode 100644
index 0000000000..33292b6eec
--- /dev/null
+++ b/frontend/pages/api/workspace/getWorkspaces.ts
@@ -0,0 +1,31 @@
+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
+ */
+const getWorkspaces = () => {
+ return SecurityClient.fetchCall("/api/v1/workspace", {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ }).then(async (res) => {
+ if (res?.status == 200) {
+ const data = (await res.json()) as unknown as { workspaces: Workspaces };
+ return data.workspaces;
+ }
+
+ throw new Error("Failed to get projects");
+ });
+};
+
+export default getWorkspaces;
diff --git a/frontend/pages/home/[id].tsx b/frontend/pages/home/[id].tsx
index 5ee7e920b4..21f15fcc37 100644
--- a/frontend/pages/home/[id].tsx
+++ b/frontend/pages/home/[id].tsx
@@ -98,22 +98,22 @@ export default function Home() {
useEffect(() => {
const checkUserActionsFunction = async () => {
- let userActionSlack = await checkUserAction({
+ const userActionSlack = await checkUserAction({
action: "slack_cta_clicked",
});
setHasUserClickedSlack(userActionSlack ? true : false);
- let userActionIntro = await checkUserAction({
+ const userActionIntro = await checkUserAction({
action: "intro_cta_clicked",
});
setHasUserClickedIntro(userActionIntro ? true : false);
- let userActionStar = await checkUserAction({
+ const userActionStar = await checkUserAction({
action: "star_cta_clicked",
});
setHasUserStarred(userActionStar ? true : false);
- let orgId = localStorage.getItem("orgData.id");
+ const orgId = localStorage.getItem("orgData.id");
const orgUsers = await getOrganizationUsers({
orgId: orgId ? orgId : "",
});
@@ -123,9 +123,9 @@ export default function Home() {
}, []);
return (
-
-
-
Your quick start guide
+
+
+
Your quick start guide
Click on the items below and follow the instructions.
{learningItem({ text: "Get to know Infisical", subText: "", complete: hasUserClickedIntro, icon: faHandPeace, time: "3 min", userAction: "intro_cta_clicked", link: "https://www.youtube.com/watch?v=JS3OKYU2078" })}
{learningItem({ text: "Add your secrets", subText: "Click to see example secrets, and add your own.", complete: false, icon: faPlus, time: "2 min", userAction: "first_time_secrets_pushed", link: "/dashboard/" + router.query.id })}
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 dfd497cd74..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) => {
- 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,
- });
+ 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"
diff --git a/frontend/pages/signupinvite.js b/frontend/pages/signupinvite.js
index 8e7f1d4a0d..15c5117395 100644
--- a/frontend/pages/signupinvite.js
+++ b/frontend/pages/signupinvite.js
@@ -92,7 +92,7 @@ export default function SignupInvite() {
},
async () => {
client.createVerifier(async (err, result) => {
- const response = await completeAccountInformationSignupInvite({
+ let response = await completeAccountInformationSignupInvite({
email,
firstName,
lastName,
@@ -291,7 +291,7 @@ export default function SignupInvite() {
)}
-
+