Skip to content

Commit e7e08fb

Browse files
authored
Merge pull request #284 from ajinkyapandetekdi/25-feb-1.4.0
Issueid #0000 added meta tag in index html file
2 parents da2deea + e7dbbd7 commit e7e08fb

File tree

8 files changed

+81
-43
lines changed

8 files changed

+81
-43
lines changed

public/index.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88
/>
99
<meta name="viewport" content="width=device-width, initial-scale=1" />
1010
<meta name="theme-color" content="#000000" />
11-
<meta http-equiv="Content-Security-Policy" content="default-src 'self';
12-
img-src 'self';
13-
script-src 'https';
14-
connect-src 'https';
15-
">
1611
<meta
1712
name="description"
1813
content="Base React App structure for Devigital Systems Projects"

src/components/Assesment/Assesment.jsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,11 @@ export const ProfileHeader = ({
352352
const handleProfileBack = () => {
353353
try {
354354
if (process.env.REACT_APP_IS_APP_IFRAME === "true") {
355-
window.parent.postMessage({ type: "restore-iframe-content" }, window?.location?.ancestorOrigins?.[0] || window.parent.location.origin);
355+
window.parent.postMessage(
356+
{ type: "restore-iframe-content" },
357+
window?.location?.ancestorOrigins?.[0] ||
358+
window.parent.location.origin
359+
);
356360
navigate("/");
357361
} else {
358362
navigate("/discover-start");
@@ -572,14 +576,14 @@ const Assesment = ({ discoverStart }) => {
572576
dispatch(setVirtualId(localStorage.getItem("virtualId")));
573577
let contentSessionId = localStorage.getItem("contentSessionId");
574578
localStorage.setItem("sessionId", contentSessionId);
575-
const TOKEN = localStorage.getItem("apiToken");
576-
let virtualId;
577-
if (TOKEN) {
578-
const tokenDetails = jwtDecode(TOKEN);
579-
virtualId = tokenDetails?.virtual_id;
580-
}
579+
// const TOKEN = localStorage.getItem("apiToken");
580+
// let virtualId;
581+
// if (TOKEN) {
582+
// const tokenDetails = jwtDecode(TOKEN);
583+
// virtualId = tokenDetails?.virtual_id;
584+
// }
581585

582-
if (discoverStart && username && !virtualId) {
586+
if (discoverStart && username && !TOKEN) {
583587
(async () => {
584588
setLocalData("profileName", username);
585589
const usernameDetails = await fetchVirtualId(username);
@@ -612,7 +616,7 @@ const Assesment = ({ discoverStart }) => {
612616
});
613617
}
614618

615-
dispatch(setVirtualId(virtualId));
619+
// dispatch(setVirtualId(virtualId));
616620
})();
617621
} else {
618622
(async () => {
@@ -634,7 +638,7 @@ const Assesment = ({ discoverStart }) => {
634638

635639
if (
636640
process.env.REACT_APP_IS_APP_IFRAME !== "true" &&
637-
virtualId &&
641+
TOKEN &&
638642
localStorage.getItem("contentSessionId") !== null
639643
) {
640644
fetchUserPoints()
@@ -652,10 +656,10 @@ const Assesment = ({ discoverStart }) => {
652656

653657
const TOKEN = localStorage.getItem("apiToken");
654658
let virtualId;
655-
if (TOKEN) {
656-
const tokenDetails = jwtDecode(TOKEN);
657-
virtualId = JSON.stringify(tokenDetails?.virtual_id);
658-
}
659+
// if (TOKEN) {
660+
// const tokenDetails = jwtDecode(TOKEN);
661+
// virtualId = JSON.stringify(tokenDetails?.virtual_id);
662+
// }
659663

660664
const handleOpenVideo = () => {
661665
if (process.env.REACT_APP_SHOW_HELP_VIDEO === "true") {
@@ -694,7 +698,7 @@ const Assesment = ({ discoverStart }) => {
694698
const navigate = useNavigate();
695699
const handleRedirect = () => {
696700
const profileName = getLocalData("profileName");
697-
if (!username && !profileName && !virtualId && level === 0) {
701+
if (!username && !profileName && !TOKEN && level === 0) {
698702
// alert("please add username in query param");
699703
setOpenMessageDialog({
700704
message: "please add username in query param",

src/csp.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export const getCSP = (envVariables) => {
2+
const {
3+
REACT_APP_HOST,
4+
REACT_APP_LEARNER_AI_BASE_URL,
5+
REACT_APP_AWS_S3_BUCKET_CONTENT_URL,
6+
REACT_APP_AWS_S3_BUCKET_URL,
7+
REACT_APP_CSP_APP_HOST,
8+
} = envVariables;
9+
10+
return `
11+
default-src 'none';
12+
manifest-src 'self';
13+
script-src 'self' blob: https://cdn.jsdelivr.net ;
14+
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://fonts.cdnfonts.com/;
15+
font-src 'self' https://fonts.gstatic.com https://fonts.cdnfonts.com;
16+
img-src 'self' data: https://images.squarespace-cdn.com ${REACT_APP_AWS_S3_BUCKET_CONTENT_URL} ${REACT_APP_AWS_S3_BUCKET_URL};
17+
media-src 'self' blob: ${REACT_APP_AWS_S3_BUCKET_URL} ${REACT_APP_AWS_S3_BUCKET_CONTENT_URL};
18+
connect-src 'self' ${REACT_APP_HOST} ${REACT_APP_LEARNER_AI_BASE_URL} ${REACT_APP_CSP_APP_HOST} blob:;
19+
form-action 'self';
20+
frame-src 'self' https://www.google.com https://www.gstatic.com;
21+
object-src 'none';
22+
base-uri 'none';
23+
`;
24+
};

src/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ import "./assets/styles/index.scss";
66
import store from "./store/configureStore";
77
import "./index.css";
88
import { BrowserRouter as Router } from "react-router-dom";
9+
import { getCSP } from "./csp";
10+
11+
const injectCSP = () => {
12+
try {
13+
const cspContent = getCSP(process.env); // Pass environment variables
14+
const metaTag = document.createElement("meta");
15+
metaTag.httpEquiv = "Content-Security-Policy";
16+
metaTag.content = cspContent.trim();
17+
document.head.appendChild(metaTag);
18+
} catch (error) {
19+
console.error("Failed to inject CSP:", error);
20+
}
21+
};
22+
23+
injectCSP();
924

1025
render(
1126
<React.StrictMode>

src/routes/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,16 @@ const routData = [
6969
];
7070
// add login route for test rig
7171
const TOKEN = localStorage.getItem("apiToken");
72-
let virtualId;
73-
if (TOKEN) {
74-
const tokenDetails = jwtDecode(TOKEN);
75-
virtualId = JSON.stringify(tokenDetails?.virtual_id);
76-
}else{
77-
virtualId = null;
78-
}
72+
// let virtualId;
73+
// if (TOKEN) {
74+
// const tokenDetails = jwtDecode(TOKEN);
75+
// virtualId = JSON.stringify(tokenDetails?.virtual_id);
76+
// }else{
77+
// virtualId = null;
78+
// }
7979
const isLogin = process.env.REACT_APP_IS_IN_APP_AUTHORISATION === "true";
8080

81-
if (isLogin && !virtualId) {
81+
if (isLogin && !TOKEN) {
8282
routData.push({
8383
id: "route-000",
8484
path: "*",

src/services/telementryService.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,12 @@ function checkTelemetryMode(currentMode) {
215215

216216
const getVirtualId = () => {
217217
const TOKEN = localStorage.getItem("apiToken");
218-
let virtualId;
219-
if (TOKEN) {
220-
const tokenDetails = jwtDecode(TOKEN);
221-
virtualId = JSON.stringify(tokenDetails?.virtual_id);
222-
}
223-
return virtualId;
218+
// let virtualId;
219+
// if (TOKEN) {
220+
// const tokenDetails = jwtDecode(TOKEN);
221+
// virtualId = JSON.stringify(tokenDetails?.virtual_id);
222+
// }
223+
return TOKEN;
224224
};
225225

226226
export const getEventOptions = () => {

src/views/AppContent/AppContent.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ import { jwtDecode } from "jwt-decode";
66
const PrivateRoute = (props) => {
77
let virtualId;
88
const TOKEN = localStorage.getItem("apiToken");
9-
if (TOKEN) {
10-
const tokenDetails = jwtDecode(TOKEN);
11-
virtualId = JSON.stringify(tokenDetails?.virtual_id);
12-
}
9+
// if (TOKEN) {
10+
// const tokenDetails = jwtDecode(TOKEN);
11+
// virtualId = JSON.stringify(tokenDetails?.virtual_id);
12+
// }
1313

1414
const navigate = useNavigate();
1515
useEffect(() => {
16-
if (!virtualId && props.requiresAuth) {
16+
if (!TOKEN && props.requiresAuth) {
1717
navigate("/login");
1818
}
19-
}, [virtualId]);
19+
}, [TOKEN]);
2020

2121
return <>{props.children}</>;
2222
};

src/views/LoginPage/LoginPage.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ const LoginPage = () => {
2323
let token = usernameDetails?.result?.token;
2424

2525
localStorage.setItem("apiToken", token);
26-
const tokenDetails = jwtDecode(token);
27-
if (tokenDetails?.virtual_id) {
26+
// const tokenDetails = jwtDecode(token);
27+
if (token) {
2828
localStorage.setItem("profileName", username);
2929
navigate("/discover-start");
3030
} else {
3131
alert("Enter correct username and password");
3232
}
3333
} catch (error) {
34-
console.error(error)
34+
console.error(error);
3535
alert("An error occurred. Please try again later.");
3636
}
3737
};

0 commit comments

Comments
 (0)