mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 09:50:15 +01:00
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
This commit is contained in:
parent
747e087cf5
commit
f5672ddcf8
10 changed files with 47 additions and 21 deletions
|
|
@ -83,7 +83,7 @@ const AuthContextProvider = ({
|
|||
setTokenHeader(token);
|
||||
setIsAuthenticated(isAuthenticated);
|
||||
if (redirect) {
|
||||
navigate(redirect);
|
||||
navigate(redirect, { replace: true });
|
||||
}
|
||||
},
|
||||
[navigate]
|
||||
|
|
@ -101,7 +101,8 @@ const AuthContextProvider = ({
|
|||
setUserContext({ token, isAuthenticated: true, user, redirect: '/chat/new' });
|
||||
},
|
||||
onError: (error) => {
|
||||
doSetError(error.message);
|
||||
doSetError((error as Error).message);
|
||||
navigate('/login', { replace: true });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
@ -122,7 +123,7 @@ const AuthContextProvider = ({
|
|||
});
|
||||
},
|
||||
onError: (error) => {
|
||||
doSetError(error.message);
|
||||
doSetError((error as Error).message);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
@ -131,9 +132,8 @@ const AuthContextProvider = ({
|
|||
if (userQuery.data) {
|
||||
setUser(userQuery.data);
|
||||
} else if (userQuery.isError) {
|
||||
//@ts-ignore - userQuery.error is of type unknown
|
||||
doSetError(userQuery?.error.message);
|
||||
navigate('/login');
|
||||
doSetError((userQuery?.error as Error).message);
|
||||
navigate('/login', { replace: true });
|
||||
}
|
||||
if (error && isAuthenticated) {
|
||||
doSetError(undefined);
|
||||
|
|
@ -143,7 +143,7 @@ const AuthContextProvider = ({
|
|||
if (tokenFromCookie) {
|
||||
setUserContext({ token: tokenFromCookie, isAuthenticated: true, user: userQuery.data });
|
||||
} else {
|
||||
navigate('/login');
|
||||
navigate('/login', { replace: true });
|
||||
}
|
||||
}
|
||||
}, [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue