From f5672ddcf8881f241306898b9c521429e069e049 Mon Sep 17 00:00:00 2001 From: Danny Avila <110412045+danny-avila@users.noreply.github.com> Date: Wed, 12 Jul 2023 11:37:27 -0400 Subject: [PATCH] Auth fix (#624) * chore(eslint): add ignore pattern for packages/data-provider/types chore(data-provider): fix import formatting in index.ts chore(data-provider): add types/index.d.ts to tsconfig include * fix(Auth): fix "skip login" bug, where UI would render in an unauthenticated state fix(Login.tsx): replace navigate('/chat/new') with navigate('/chat/new', { replace: true }) fix(AuthContext.tsx): replace navigate(redirect) with navigate(redirect, { replace: true }) fix(AuthContext.tsx): replace navigate('/login') with navigate('/login', { replace: true }) fix(AuthContext.tsx): replace navigate('/login') with navigate('/login', { replace: true }) fix(routes/Chat.jsx): add check for isAuthenticated: navigate to '/login' and render null if not authenticated fix(routes/index.jsx): add check for isAuthenticated: navigate to '/login' and render null if not authenticated * refactor(SubmitButton.jsx): create a set of endpoints to hide set tokens fix(SubmitButton.jsx): fix condition to check if token is provided for certain endpoints --- .eslintrc.js | 3 ++ client/src/components/Auth/Login.tsx | 2 +- client/src/components/Input/SubmitButton.jsx | 3 +- client/src/hooks/AuthContext.tsx | 14 ++++----- client/src/routes/Chat.jsx | 32 +++++++++++++++----- client/src/routes/Root.jsx | 6 +++- client/src/routes/Search.jsx | 2 +- client/src/routes/index.jsx | 2 +- packages/data-provider/src/index.ts | 2 +- packages/data-provider/tsconfig.json | 2 +- 10 files changed, 47 insertions(+), 21 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 3dddeb8ea..72ed417d5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -13,6 +13,9 @@ module.exports = { 'plugin:jest/recommended', 'prettier' ], + ignorePatterns: [ + 'packages/data-provider/types/**/*', + ], parser: '@typescript-eslint/parser', parserOptions: { ecmaVersion: 'latest', diff --git a/client/src/components/Auth/Login.tsx b/client/src/components/Auth/Login.tsx index 2999c6a22..5e7562bbc 100644 --- a/client/src/components/Auth/Login.tsx +++ b/client/src/components/Auth/Login.tsx @@ -19,7 +19,7 @@ function Login() { useEffect(() => { if (isAuthenticated) { - navigate('/chat/new'); + navigate('/chat/new', { replace: true }); } }, [isAuthenticated, navigate]); diff --git a/client/src/components/Input/SubmitButton.jsx b/client/src/components/Input/SubmitButton.jsx index 6f80277ff..44c892d64 100644 --- a/client/src/components/Input/SubmitButton.jsx +++ b/client/src/components/Input/SubmitButton.jsx @@ -16,6 +16,7 @@ export default function SubmitButton({ const { getToken } = store.useToken(endpoint); const isTokenProvided = endpointsConfig?.[endpoint]?.userProvide ? !!getToken() : true; + const endpointsToHideSetTokens = new Set(['openAI', 'azureOpenAI', 'bingAI']); const clickHandler = (e) => { e.preventDefault(); @@ -38,7 +39,7 @@ export default function SubmitButton({ ); - } else if (!isTokenProvided && (endpoint !== 'openAI' || endpoint !== 'azureOpenAI' )) { + } else if (!isTokenProvided && (!endpointsToHideSetTokens.has(endpoint))) { return ( <>