Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit a84d310

Browse files
#630 - cleanup code
1 parent cdd790e commit a84d310

File tree

8 files changed

+21
-27
lines changed

8 files changed

+21
-27
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
node_modules
22
.idea
33
**/.DS_Store
4-
upload
54
scripts/generate
65
.nyc_output
76
.env

client/README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@ REACT_APP_ATTRIBUTE_ID_COMPANY
1616
REACT_APP_ATTRIBUTE_ID_TITLE
1717
REACT_APP_ATTRIBUTE_ID_ISAVAILABLE
1818
=> All 4 of the above are the ids of the attributes with name "location", "company", "title" and "isAvailable" respectively. These are used to filter attributes for display under a dedicated section named company attributes. Since these already have UI elements of their own, they are filtered from the list of company attributes
19-
REACT_APP_AUTH0_DOMAIN => The Auth0 login domain
20-
REACT_APP_AUTH0_CLIENTID => The Auth0 clientId
19+
REACT_APP_ACCOUNTS_APP_CONNECTOR
20+
REACT_APP_TC_AUTH_URL
21+
=> The connection parameters to authenticate with Topcoder
22+
REACT_APP_APP_URL
23+
=> The app's url. ex. http://localhost:3000. This is used to redirect the user after they have logged in
24+
REACT_APP_AUTH0_CLAIMS_HANDLE
25+
=> The property name in decoded token object to read the nickname from
26+
REACT_APP_TC_COOKIE_NAME
27+
=> The topcoder cookie name. App uses this to detect if the user has token or not
2128
```
2229

2330
You can create a `.env.local` file and provide the above configuration. Note that there's more configuration that you can change and you can find this under `src/config.js`. The above configurations are the minimum ones, that you need to launch the app successfully.

client/src/Router.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ configureConnector({
2424
export default function AppRouter() {
2525
const [loading, setLoading] = React.useState(true);
2626

27+
/**
28+
* The auth checks would ideally be under Private Routes
29+
* However, our app does not have any routes (only / route)
30+
* and thus adding the code on the ROOT route itself...
31+
*/
2732
React.useEffect(() => {
2833
if (!loading) {
2934
return;
3035
}
3136

3237
(async () => {
33-
console.log("Getting token in router");
3438
try {
3539
await getFreshToken();
36-
console.log("Received token in router");
3740

3841
setLoading(false);
3942
} catch (error) {

client/src/components/Upload/index.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import style from "./style.module.scss";
1414
import config from "../../config";
1515
import api from "../../services/api";
1616
import { getSingleOrg } from "../../services/user-org";
17-
import { ConsoleTransportOptions } from "winston/lib/winston/transports";
1817

1918
const UPLOAD_STATES = {
2019
INITIAL: "INITIAL",

client/src/config.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,14 @@ export default {
3232
isAvailable: process.env.REACT_APP_ATTRIBUTE_ID_ISAVAILABLE,
3333
},
3434

35-
// TODO - Search and remove references before deleting below code
36-
// AUTH0: {
37-
// domain: process.env.REACT_APP_AUTH0_DOMAIN,
38-
// clientId: process.env.REACT_APP_AUTH0_CLIENTID,
39-
// audience: process.env.REACT_APP_AUTH0_AUDIENCE,
40-
// handleClaims: process.env.REACT_APP_AUTH0_CLAIMS_HANDLE,
41-
// },
4235
AUTH: {
4336
ACCOUNTS_APP_CONNECTOR: process.env.REACT_APP_ACCOUNTS_APP_CONNECTOR,
4437
TC_AUTH_URL: process.env.REACT_APP_TC_AUTH_URL,
38+
// redirect to url after login
4539
APP_URL: process.env.REACT_APP_APP_URL,
40+
// property name in decoded token object to read the nickname from
4641
handleClaims: process.env.REACT_APP_AUTH0_CLAIMS_HANDLE,
42+
// cookie name which contains the TC token
43+
cookieName: process.env.REACT_APP_TC_COOKIE_NAME || "v3jwt",
4744
},
4845
};

client/src/lib/common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ export async function getNickname() {
1515
"An error occurred trying to retrieve the nickname of the logged in user"
1616
);
1717
console.log(error);
18-
alert("You are not logged in");
18+
alert("An error occurred. Try logging out and then log back in");
1919
}
2020
}

client/src/pages/Search/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default function SearchPage() {
5757
}, [keyword]);
5858

5959
const onSelectOrg = (org) => {
60-
const cookie = Cookies.get("v3jwt");
60+
const cookie = Cookies.get(config.AUTH.cookieName);
6161
if (cookie) {
6262
OrgService.setSingleOrg(org);
6363
setSelectedOrg(org);

client/src/services/api.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
import { useRef, useEffect } from "react";
66
import axios from "axios";
7-
import { getFreshToken, isTokenExpired } from "@topcoder-platform/tc-auth-lib";
8-
import Cookies from "js-cookie";
7+
import { getFreshToken } from "@topcoder-platform/tc-auth-lib";
98

109
import config from "../config";
1110

@@ -24,23 +23,13 @@ export default () => {
2423
})
2524
);
2625
useEffect(() => {
27-
const cookie = Cookies.get("v3jwt");
28-
if (cookie) {
29-
// Do nothing
30-
} else {
31-
console.log("Inside api, cookie not found. Forcing login");
32-
forceLogin();
33-
return;
34-
}
3526
const currentAPI = api.current;
3627
currentAPI.interceptors.request.use(async (config) => {
3728
let token;
3829
if (process.env.REACT_APP_DEV_TOKEN) {
3930
token = process.env.REACT_APP_DEV_TOKEN;
4031
} else {
41-
console.log("Inside api. Request intercepted. Attaching token");
4232
token = await getFreshToken();
43-
console.log("Is token expired:", isTokenExpired(token));
4433
}
4534
config.headers.authorization = `Bearer ${token}`;
4635
return config;

0 commit comments

Comments
 (0)