diff --git a/frontend/src/components/login/InitialLoginStep.tsx b/frontend/src/components/login/InitialLoginStep.tsx
index 6b39f8ece..5f17b1cf9 100644
--- a/frontend/src/components/login/InitialLoginStep.tsx
+++ b/frontend/src/components/login/InitialLoginStep.tsx
@@ -1,16 +1,16 @@
-import { useState } from 'react';
-import { useTranslation } from 'react-i18next';
-import Link from 'next/link';
-import { useRouter } from 'next/router';
+import { useState } from "react";
+import { useTranslation } from "react-i18next";
+import Link from "next/link";
+import { useRouter } from "next/router";
import axios from "axios"
import attemptLogin from "@app/components/utilities/attemptLogin";
import Error from "../basic/Error";
+import attemptCliLogin from "../utilities/attemptCliLogin";
// import { faGoogle } from '@fortawesome/free-brands-svg-icons';
// import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
-import { Button, Input } from '../v2';
-import attemptCliLogin from '../utilities/attemptCliLogin';
+import { Button, Input } from "../v2";
export default function InitialLoginStep({
setStep,
@@ -38,11 +38,11 @@ export default function InitialLoginStep({
}
setIsLoading(true);
- const queryParams = new URLSearchParams(location.search)
+ const queryParams = new URLSearchParams(window.location.search)
if (queryParams && queryParams.get("callback_port")) {
const callbackPort = queryParams.get("callback_port")
- //attemptCliLogin
+ // attemptCliLogin
const isCliLoginSuccessful = await attemptCliLogin({
email,
password,
@@ -59,15 +59,15 @@ export default function InitialLoginStep({
// case: login was successful
const cliUrl = `http://localhost:${callbackPort}`
- //send request to server endpoint
+ // send request to server endpoint
const instance = axios.create()
- const cliResp = await instance.post(cliUrl,{...isCliLoginSuccessful.loginResponse})
+ const cliResp = await instance.post(cliUrl, { ...isCliLoginSuccessful.loginResponse })
console.log(cliResp)
- //cli page
+ // cli page
router.push("/cli-redirect");
- //on success, router.push to cli Login Successful page
+ // on success, router.push to cli Login Successful page
}
} else {
@@ -86,7 +86,7 @@ export default function InitialLoginStep({
}
// case: login does not require MFA step
- router.push(`/dashboard/${localStorage.getItem('projectData.id')}`);
+ router.push(`/dashboard/${localStorage.getItem("projectData.id")}`);
}
}
@@ -127,18 +127,18 @@ export default function InitialLoginStep({
{!isLoading && loginError && }
diff --git a/frontend/src/components/login/MFAStep.tsx b/frontend/src/components/login/MFAStep.tsx
index 7ae7c7781..2408ad0b1 100644
--- a/frontend/src/components/login/MFAStep.tsx
+++ b/frontend/src/components/login/MFAStep.tsx
@@ -1,13 +1,13 @@
/* eslint-disable react/jsx-props-no-spreading */
-import React, { useState } from 'react';
-import ReactCodeInput from 'react-code-input';
-import { useTranslation } from 'react-i18next';
-import { useRouter } from 'next/router';
+import React, { useState } from "react";
+import ReactCodeInput from "react-code-input";
+import { useTranslation } from "react-i18next";
+import { useRouter } from "next/router";
import axios from "axios"
-import attemptLoginMfa from '@app/components/utilities/attemptLoginMfa';
-import attemptCliLoginMfa from '@app/components/utilities/attemptCliLoginMfa'
-import { useSendMfaToken } from '@app/hooks/api/auth';
+import attemptCliLoginMfa from "@app/components/utilities/attemptCliLoginMfa"
+import attemptLoginMfa from "@app/components/utilities/attemptLoginMfa";
+import { useSendMfaToken } from "@app/hooks/api/auth";
import Error from "../basic/Error";
import { Button } from "../v2";
@@ -78,11 +78,11 @@ export default function MFAStep({
}
setIsLoading(true);
- const queryParams = new URLSearchParams(location.search)
+ const queryParams = new URLSearchParams(window.location.search)
if (queryParams && queryParams.get("callback_port")){
const callbackPort = queryParams.get("callback_port")
- //attemptCliLogin
+ // attemptCliLogin
const isCliLoginSuccessful = await attemptCliLoginMfa({
email,
password,
@@ -94,11 +94,11 @@ export default function MFAStep({
// case: login was successful
const cliUrl = `http://localhost:${callbackPort}`
- //send request to server endpoint
+ // send request to server endpoint
const instance = axios.create()
- const cliResp = await instance.post(cliUrl,{...isCliLoginSuccessful.loginResponse,email})
+ await instance.post(cliUrl,{...isCliLoginSuccessful.loginResponse,email})
- //cli page
+ // cli page
router.push("/cli-redirect");
}
}else{
@@ -111,7 +111,7 @@ export default function MFAStep({
if (isLoginSuccessful) {
setIsLoading(false);
- router.push(`/dashboard/${localStorage.getItem('projectData.id')}`);
+ router.push(`/dashboard/${localStorage.getItem("projectData.id")}`);
}
}
diff --git a/frontend/src/components/utilities/attemptCliLogin.ts b/frontend/src/components/utilities/attemptCliLogin.ts
index f6427e36f..099351baa 100644
--- a/frontend/src/components/utilities/attemptCliLogin.ts
+++ b/frontend/src/components/utilities/attemptCliLogin.ts
@@ -1,15 +1,15 @@
/* eslint-disable prefer-destructuring */
-import jsrp from 'jsrp';
+import jsrp from "jsrp";
-import login1 from '@app/pages/api/auth/Login1';
-import login2 from '@app/pages/api/auth/Login2';
-import getOrganizations from '@app/pages/api/organization/getOrgs';
-import getOrganizationUserProjects from '@app/pages/api/organization/GetOrgUserProjects';
-import KeyService from '@app/services/KeyService';
+import login1 from "@app/pages/api/auth/Login1";
+import login2 from "@app/pages/api/auth/Login2";
+import getOrganizations from "@app/pages/api/organization/getOrgs";
+import getOrganizationUserProjects from "@app/pages/api/organization/GetOrgUserProjects";
+import KeyService from "@app/services/KeyService";
-import Telemetry from './telemetry/Telemetry';
-import { saveTokenToLocalStorage } from './saveTokenToLocalStorage';
-import SecurityClient from './SecurityClient';
+import Telemetry from "./telemetry/Telemetry";
+import { saveTokenToLocalStorage } from "./saveTokenToLocalStorage";
+import SecurityClient from "./SecurityClient";
// eslint-disable-next-line new-cap
const client = new jsrp.client();
@@ -101,7 +101,7 @@ const attemptLogin = async (
// case: MFA is not enabled
// unset provider auth token in case it was used
- SecurityClient.setProviderAuthToken('');
+ SecurityClient.setProviderAuthToken("");
// set JWT token
SecurityClient.setToken(token);
@@ -117,11 +117,36 @@ const attemptLogin = async (
protectedKeyTag
});
+ saveTokenToLocalStorage({
+ publicKey,
+ encryptedPrivateKey,
+ iv,
+ tag,
+ privateKey
+ });
+
+ const userOrgs = await getOrganizations();
+ const orgId = userOrgs[0]._id;
+ localStorage.setItem("orgData.id", orgId);
+
+ const orgUserProjects = await getOrganizationUserProjects({
+ orgId
+ });
+
+ if (orgUserProjects.length > 0) {
+ localStorage.setItem("projectData.id", orgUserProjects[0]._id);
+ }
+
+ if (email) {
+ telemetry.identify(email, email);
+ telemetry.capture("User Logged In");
+ }
+
resolve({
mfaEnabled: false,
loginResponse: {
- email: email,
- privateKey: privateKey,
+ email,
+ privateKey,
JTWToken: token
},
success: true
diff --git a/frontend/src/components/utilities/attemptCliLoginMfa.ts b/frontend/src/components/utilities/attemptCliLoginMfa.ts
index e4143edbb..cb33d3bad 100644
--- a/frontend/src/components/utilities/attemptCliLoginMfa.ts
+++ b/frontend/src/components/utilities/attemptCliLoginMfa.ts
@@ -1,19 +1,19 @@
/* eslint-disable prefer-destructuring */
-import jsrp from 'jsrp';
+import jsrp from "jsrp";
-import login1 from '@app/pages/api/auth/Login1';
-import verifyMfaToken from '@app/pages/api/auth/verifyMfaToken';
-import getOrganizations from '@app/pages/api/organization/getOrgs';
-import getOrganizationUserProjects from '@app/pages/api/organization/GetOrgUserProjects';
-import KeyService from '@app/services/KeyService';
+import login1 from "@app/pages/api/auth/Login1";
+import verifyMfaToken from "@app/pages/api/auth/verifyMfaToken";
+import getOrganizations from "@app/pages/api/organization/getOrgs";
+import getOrganizationUserProjects from "@app/pages/api/organization/GetOrgUserProjects";
+import KeyService from "@app/services/KeyService";
-import { saveTokenToLocalStorage } from './saveTokenToLocalStorage';
-import SecurityClient from './SecurityClient';
+import { saveTokenToLocalStorage } from "./saveTokenToLocalStorage";
+import SecurityClient from "./SecurityClient";
// eslint-disable-next-line new-cap
const client = new jsrp.client();
-interface isMfaLoginSuccessful {
+interface IsMfaLoginSuccessful {
success: boolean;
loginResponse:{
privateKey: string;
@@ -39,7 +39,7 @@ const attemptLoginMfa = async ({
password: string;
providerAuthToken?: string,
mfaToken: string;
-}): Promise
=> {
+}): Promise => {
return new Promise((resolve, reject) => {
client.init({
username: email,
@@ -69,9 +69,9 @@ const attemptLoginMfa = async ({
});
// unset temporary (MFA) JWT token and set JWT token
- SecurityClient.setMfaToken('');
+ SecurityClient.setMfaToken("");
SecurityClient.setToken(token);
- SecurityClient.setProviderAuthToken('');
+ SecurityClient.setProviderAuthToken("");
const privateKey = await KeyService.decryptPrivateKey({
encryptionVersion,
@@ -98,17 +98,17 @@ const attemptLoginMfa = async ({
// and not initializing the login details
const userOrgs = await getOrganizations();
const orgId = userOrgs[0]._id;
- localStorage.setItem('orgData.id', orgId);
+ localStorage.setItem("orgData.id", orgId);
const orgUserProjects = await getOrganizationUserProjects({
orgId
});
- localStorage.setItem('projectData.id', orgUserProjects[0]._id);
+ localStorage.setItem("projectData.id", orgUserProjects[0]._id);
resolve({
success: true,
loginResponse:{
- privateKey: privateKey,
+ privateKey,
JTWToken: token
}
});
diff --git a/frontend/src/hooks/api/users/queries.tsx b/frontend/src/hooks/api/users/queries.tsx
index d48aa07af..9baf7b784 100644
--- a/frontend/src/hooks/api/users/queries.tsx
+++ b/frontend/src/hooks/api/users/queries.tsx
@@ -25,7 +25,7 @@ const userKeys = {
};
export const fetchUserDetails = async () => {
- const { data } = await apiRequest.get<{ user: User }>('/api/v1/user');
+ const { data } = await apiRequest.get<{ user: User }>("/api/v1/user");
return data.user;
};
diff --git a/frontend/src/pages/cli-redirect.tsx b/frontend/src/pages/cli-redirect.tsx
index 076174b67..889a31dcc 100644
--- a/frontend/src/pages/cli-redirect.tsx
+++ b/frontend/src/pages/cli-redirect.tsx
@@ -1,6 +1,5 @@
-import Head from 'next/head';
-import Image from 'next/image';
-import Link from 'next/link';
+import Head from "next/head";
+import Image from "next/image";
export default function CliRedirect() {
return (
@@ -12,7 +11,7 @@ export default function CliRedirect() {
Head back to your terminal!
- You've successfully logged into infisical-cli
+ You've successfully logged into infisical-cli