From eabe56da9d2fbebc0a13175353e690fe6c95e216 Mon Sep 17 00:00:00 2001 From: David Lyon Date: Thu, 18 Jul 2024 14:18:20 -0700 Subject: [PATCH] support new login paths --- src/app/Routes.tsx | 11 ++++++++--- src/features/layout/TopBar.tsx | 3 ++- src/features/login/LogIn.tsx | 6 +++--- src/features/login/LogInContinue.tsx | 7 +------ src/features/params/paramsSlice.ts | 4 +++- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/app/Routes.tsx b/src/app/Routes.tsx index 4ec9ee7b..79f11c56 100644 --- a/src/app/Routes.tsx +++ b/src/app/Routes.tsx @@ -1,5 +1,6 @@ import { FC, ReactElement } from 'react'; import { + createSearchParams, Navigate, Route, Routes as RRRoutes, @@ -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 = () => { @@ -124,9 +125,13 @@ export const Authed: FC<{ element: ReactElement }> = ({ element }) => { if (!token) return ( ); diff --git a/src/features/layout/TopBar.tsx b/src/features/layout/TopBar.tsx index 49df4584..2489ed6f 100644 --- a/src/features/layout/TopBar.tsx +++ b/src/features/layout/TopBar.tsx @@ -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); @@ -57,7 +58,7 @@ export default function TopBar() { } const LoginPrompt: FC = () => ( - + Sign In diff --git a/src/features/login/LogIn.tsx b/src/features/login/LogIn.tsx index 90ad9498..3202fc96 100644 --- a/src/features/login/LogIn.tsx +++ b/src/features/login/LogIn.tsx @@ -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 = @@ -45,7 +45,7 @@ export const LogIn: FC = () => { ).toString(); const loginState = encodeURIComponent( JSON.stringify({ - nextrequest: nextRequest, + nextRequest: nextRequest, origin: loginOrigin, }) ); diff --git a/src/features/login/LogInContinue.tsx b/src/features/login/LogInContinue.tsx index 53d3e8d8..11a5cd70 100644 --- a/src/features/login/LogInContinue.tsx +++ b/src/features/login/LogInContinue.tsx @@ -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'; @@ -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(); diff --git a/src/features/params/paramsSlice.ts b/src/features/params/paramsSlice.ts index 610d1385..f5972f98 100644 --- a/src/features/params/paramsSlice.ts +++ b/src/features/params/paramsSlice.ts @@ -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, @@ -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