Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After login - after using the application as an unauthenticated user - I am directed to the unauth view of the page #593

Merged
merged 3 commits into from
Oct 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions app/src/pages/public/PublicProjectPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ import Icon from '@mdi/react';
import { DATE_FORMAT } from 'constants/dateTimeFormats';
import { useBiohubApi } from 'hooks/useBioHubApi';
import { IGetProjectForViewResponse } from 'interfaces/useProjectApi.interface';
import React, { useCallback, useEffect, useState } from 'react';
import { useParams, useLocation } from 'react-router';
import React, { useCallback, useContext, useEffect, useState } from 'react';
import { useParams, useLocation, useHistory } from 'react-router';
import { NavLink } from 'react-router-dom';
import { getFormattedDateRangeString } from 'utils/Utils';
import { ProjectStatusType } from 'constants/misc';
import Chip from '@material-ui/core/Chip';
import clsx from 'clsx';
import PublicProjectDetails from './PublicProjectDetails';
import PublicProjectAttachments from './components/PublicProjectAttachments';
import { isAuthenticated } from 'utils/authUtils';
import { AuthStateContext } from 'contexts/authStateContext';

const useStyles = makeStyles((theme: Theme) => ({
projectNav: {
Expand Down Expand Up @@ -67,6 +69,8 @@ const PublicProjectPage = () => {
const biohubApi = useBiohubApi();
const classes = useStyles();
const location = useLocation();
const { keycloakWrapper } = useContext(AuthStateContext);
const history = useHistory();

const [isLoadingProject, setIsLoadingProject] = useState(false);
const [projectWithDetails, setProjectWithDetails] = useState<IGetProjectForViewResponse | null>(null);
Expand Down Expand Up @@ -104,6 +108,10 @@ const PublicProjectPage = () => {
return <Chip className={clsx(classes.chip, chipStatusClass)} label={chipLabel} />;
};

if (isAuthenticated(keycloakWrapper)) {
history.push(`/admin/projects/${urlParams['id']}/details`);
}

if (!projectWithDetails) {
return <CircularProgress className="pageProgress" size={40} />;
}
Expand Down