diff --git a/src/context/sasContext.tsx b/src/context/sasContext.tsx index fb52c05..042bffb 100644 --- a/src/context/sasContext.tsx +++ b/src/context/sasContext.tsx @@ -100,14 +100,11 @@ const SASProvider = (props: { children: ReactNode }) => { }, []) const login = useCallback(async (username, password) => { - const clientId = - sasjsConfig.serverType === ServerType.Sasjs - ? process.env.REACT_APP_CLIENT_ID - : undefined return sasService - .logIn(username, password, clientId) + .logIn(username, password) .then( (res: LoginResult) => { + setUserName(res.userName) setIsUserLoggedIn(res.isLoggedIn) return true }, @@ -128,6 +125,8 @@ const SASProvider = (props: { children: ReactNode }) => { const logout = useCallback(() => { sasService.logOut().then(() => { setIsUserLoggedIn(false) + setFullName('') + setUserName('') }) }, []) @@ -137,10 +136,16 @@ const SASProvider = (props: { children: ReactNode }) => { useEffect(() => { setCheckingSession(true) - sasService.checkSession().then((response) => { - setCheckingSession(false) - setIsUserLoggedIn(response.isLoggedIn) - }) + sasService + .checkSession() + .then((response) => { + setCheckingSession(false) + setIsUserLoggedIn(response.isLoggedIn) + }) + .catch((_) => { + setCheckingSession(false) + setIsUserLoggedIn(false) + }) }, []) useEffect(() => { diff --git a/src/layouts/Main.jsx b/src/layouts/Main.jsx index 1c8ed6a..cd79269 100644 --- a/src/layouts/Main.jsx +++ b/src/layouts/Main.jsx @@ -124,7 +124,7 @@ const Main = (props) => { }} > { Documentation - - - + {sasContext.isUserLoggedIn && ( + + + + )}