Skip to content

Commit

Permalink
Fix for Annon search (no login)
Browse files Browse the repository at this point in the history
Changes to be committed:
	modified:   client/src/components/bcodbs/SearchOptions.js
	modified:   client/src/services/auth.service.js
  • Loading branch information
HadleyKing committed Apr 26, 2024
1 parent 9740dc5 commit 0fb00a5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
5 changes: 4 additions & 1 deletion client/src/components/bcodbs/SearchOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import { styled } from "@mui/material/styles";
import IconButton from "@mui/material/IconButton";
import Collapse from "@mui/material/Collapse";

const bcodbUrl = process.env.REACT_APP_BCOAPI_URL
const publicHostname = bcodbUrl.replace("/api/", "")

const ExpandMore = styled((props) => {
const { expand, ...other } = props;
return <IconButton {...other} />;
Expand Down Expand Up @@ -75,7 +78,7 @@ export default function SearchOptions ({setBcodbInfo}) {
if (values.index === "None") {
const data = {
token: "627626823549f787c3ec763ff687169206626149",
public_hostname: "https://biocomputeobject.org",
public_hostname: publicHostname,
search: values.search,
action: "bco_id"
}
Expand Down
30 changes: 15 additions & 15 deletions client/src/services/auth.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const USERS_URL = process.env.REACT_APP_USERDB_URL;
const BCODB_URL = process.env.REACT_APP_BCOAPI_URL;

function getCsrfToken() {
const csrfToken = document.cookie.split('; ')
.find(row => row.startsWith('csrftoken='))
?.split('=')[1];
const csrfToken = global.document.cookie.split("; ")
.find(row => row.startsWith("csrftoken="))
?.split("=")[1];
return csrfToken;
}

Expand Down Expand Up @@ -41,23 +41,23 @@ const login = async (username, password) => {
const googleLogin = async (idToken) => {
const csrfToken = getCsrfToken(); // Fetch the CSRF token
const headers = {
'Content-Type': 'application/json',
'X-CSRFToken': csrfToken // Include the CSRF token in the request header
"Content-Type": "application/json",
"X-CSRFToken": csrfToken // Include the CSRF token in the request header
};

try {
const response = await axios.post(USERS_URL + "google/login/", {
id_token: idToken
}, { headers });
const response = await axios.post(USERS_URL + "google/login/", {
id_token: idToken
}, { headers });

if (response.data.token) {
localStorage.setItem("user", JSON.stringify(response.data.user));
localStorage.setItem("token", JSON.stringify(response.data.token));
}
return response.data;
if (response.data.token) {
localStorage.setItem("user", JSON.stringify(response.data.user));
localStorage.setItem("token", JSON.stringify(response.data.token));
}
return response.data;
} catch (error) {
console.error("Login failed:", error.response || error.message);
throw error;
console.error("Login failed:", error.response || error.message);
throw error;
}
};

Expand Down

0 comments on commit 0fb00a5

Please sign in to comment.