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

Commit f44a64b

Browse files
Merge branch 'develop' of github.com:topcoder-platform/u-bahn-app into develop
2 parents 3097756 + fc1076d commit f44a64b

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

client/package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"form-data": "^3.0.0",
1313
"history": "^4.10.1",
1414
"husky": "^4.2.5",
15+
"js-cookies": "^1.0.4",
1516
"lint-staged": "^10.2.6",
1617
"lodash": "^4.17.15",
1718
"node-sass": "^4.14.1",

client/src/pages/Search/index.jsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ import { useAuth0 } from "../../react-auth0-spa";
1717
import * as OrgService from "../../services/user-org";
1818
import api from "../../services/api";
1919

20+
import Cookies from "js-cookie";
21+
2022
export default function SearchPage() {
2123
const apiClient = api();
22-
const { isLoading, isAuthenticated, user: auth0User } = useAuth0();
24+
const { isLoading, isAuthenticated, user: auth0User, loginWithRedirect } = useAuth0();
2325
const [tab, setTab] = React.useState(TABS.SEARCH);
2426
const [keyword, setKeyword] = React.useState(null);
2527
const [selectedOrg, setSelectedOrg] = React.useState(null);
@@ -62,9 +64,16 @@ export default function SearchPage() {
6264
}, [keyword]);
6365

6466
const onSelectOrg = (org) => {
65-
OrgService.setSingleOrg(org);
66-
setSelectedOrg(org);
67-
setShouldSelectOrg(false);
67+
const cookie = Cookies.get('auth0.is.authenticated');
68+
if (cookie && cookie === 'true') {
69+
OrgService.setSingleOrg(org);
70+
setSelectedOrg(org);
71+
setShouldSelectOrg(false);
72+
} else {
73+
loginWithRedirect({
74+
redirect_uri: window.location.origin,
75+
});
76+
}
6877
};
6978

7079
let mainContent;

client/src/services/api.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import axios from "axios";
77

88
import { useAuth0 } from "../react-auth0-spa";
99

10+
import Cookies from "js-cookie";
11+
1012
export default () => {
1113
const { getTokenSilently, loginWithRedirect } = useAuth0();
1214
const api = useRef(
@@ -17,6 +19,15 @@ export default () => {
1719
})
1820
);
1921
useEffect(() => {
22+
const cookie = Cookies.get('auth0.is.authenticated');
23+
if (cookie && cookie === 'true') {
24+
// Do nothing
25+
} else {
26+
loginWithRedirect({
27+
redirect_uri: window.location.origin,
28+
});
29+
return;
30+
}
2031
const currentAPI = api.current;
2132
currentAPI.interceptors.request.use(async (config) => {
2233
let token;

0 commit comments

Comments
 (0)