Skip to content

Commit

Permalink
support new login paths
Browse files Browse the repository at this point in the history
  • Loading branch information
dauglyon committed Jul 18, 2024
1 parent e9967cd commit eabe56d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
11 changes: 8 additions & 3 deletions src/app/Routes.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FC, ReactElement } from 'react';
import {
createSearchParams,
Navigate,
Route,
Routes as RRRoutes,
Expand Down Expand Up @@ -30,7 +31,7 @@ import { LogIn } from '../features/login/LogIn';
import { LogInContinue } from '../features/login/LogInContinue';
import ORCIDLinkCreateLink from '../features/orcidlink/CreateLink';

export const LOGIN_ROUTE = '/legacy/login';
export const LOGIN_ROUTE = '/login';
export const ROOT_REDIRECT_ROUTE = '/narratives';

const Routes: FC = () => {
Expand Down Expand Up @@ -124,9 +125,13 @@ export const Authed: FC<{ element: ReactElement }> = ({ element }) => {
if (!token)
return (
<Navigate
to={LOGIN_ROUTE}
to={{
pathname: LOGIN_ROUTE,
search: createSearchParams({
nextRequest: JSON.stringify(location),
}).toString(),
}}
replace
state={{ preLoginPath: location.pathname }}
/>
);

Expand Down
3 changes: 2 additions & 1 deletion src/features/layout/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { useAppDispatch, useAppSelector } from '../../common/hooks';
import { authUsername, setAuth } from '../auth/authSlice';
import { noOp } from '../common';
import classes from './TopBar.module.scss';
import { LOGIN_ROUTE } from '../../app/Routes';

export default function TopBar() {
const username = useAppSelector(authUsername);
Expand All @@ -57,7 +58,7 @@ export default function TopBar() {
}

const LoginPrompt: FC = () => (
<Link role="button" to={'/legacy/login'} className={classes.login_prompt}>
<Link role="button" to={LOGIN_ROUTE} className={classes.login_prompt}>
<FAIcon icon={faSignIn} />
<span>Sign In</span>
</Link>
Expand Down
6 changes: 3 additions & 3 deletions src/features/login/LogIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ export const useCheckLoggedIn = () => {

const navigate = useNavigate();
if (token && initialized) {
// TODO: handle nextrequest
// TODO: handle nextRequest
navigate('/narratives');
}
};

export const LogIn: FC = () => {
useCheckLoggedIn();
const nextRequest = useAppParam('nextrequest');
const nextRequest = useAppParam('nextRequest');

// OAuth Login wont work in dev mode, but send dev users to CI so they can grab their token
const loginOrigin =
Expand All @@ -45,7 +45,7 @@ export const LogIn: FC = () => {
).toString();
const loginState = encodeURIComponent(
JSON.stringify({
nextrequest: nextRequest,
nextRequest: nextRequest,
origin: loginOrigin,
})
);
Expand Down
7 changes: 1 addition & 6 deletions src/features/login/LogInContinue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { FC, useEffect } from 'react';
import logoRectangle from '../../common/assets/logo/rectangle.png';
import classes from './LogIn.module.scss';
import { Loader } from '../../common/components';
import { useCookie } from '../../common/cookie';
import { getLoginChoice, postLoginPick } from '../../common/api/authService';
import { useTryAuthFromToken } from '../auth/hooks';
import { useCheckLoggedIn } from './LogIn';
Expand All @@ -12,11 +11,7 @@ export const LogInContinue: FC = () => {
// redirect if/when login is completed
useCheckLoggedIn();

const [loginProcessToken] = useCookie('in-process-login-token');

const { data: choiceData } = getLoginChoice.useQuery(undefined, {
skip: !loginProcessToken,
});
const { data: choiceData } = getLoginChoice.useQuery();

const [trigger, result] = postLoginPick.useMutation();

Expand Down
4 changes: 3 additions & 1 deletion src/features/params/paramsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type { RootState } from '../../app/store';
// Define a type for the slice state
class ParamsClass {
constructor(
// For Auth/Login/Linking
readonly nextRequest: string | null = null,
// Search
readonly limit: string | null = '20',
readonly search: string | null = null,
Expand All @@ -28,7 +30,7 @@ class ParamsClass {
// For narrative opening
readonly n: string | null = null,
readonly check: string | null = null,
// For kbase-ui navigation via auth
// For kbase-ui navigation via auth in an iframe
readonly nextrequest: string | null = null,
readonly source: string | null = null,
// for account management ui
Expand Down

0 comments on commit eabe56d

Please sign in to comment.