Files
frontend-app-authn/src/common-components/UnAuthOnlyRoute.jsx
dependabot[bot] 06dd70078e build(deps): bump http-cache-semantics and @edx/frontend-build (#791)
Removes [http-cache-semantics](https://github.com/kornelski/http-cache-semantics). It's no longer used after updating ancestor dependency [@edx/frontend-build](https://github.com/openedx/frontend-build). These dependencies need to be updated together.


Removes `http-cache-semantics`

Updates `@edx/frontend-build` from 11.0.2 to 12.7.0
- [Release notes](https://github.com/openedx/frontend-build/releases)
- [Commits](https://github.com/openedx/frontend-build/compare/v11.0.2...v12.7.0)

---
updated-dependencies:
- dependency-name: http-cache-semantics
  dependency-type: indirect
- dependency-name: "@edx/frontend-build"
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-31 13:33:44 +05:00

37 lines
1007 B
JavaScript

import React, { useEffect, useState } from 'react';
import { getConfig } from '@edx/frontend-platform';
import { fetchAuthenticatedUser, getAuthenticatedUser } from '@edx/frontend-platform/auth';
import { Route } from 'react-router-dom';
import { DEFAULT_REDIRECT_URL } from '../data/constants';
/**
* This wrapper redirects the requester to our default redirect url if they are
* already authenticated.
*/
const UnAuthOnlyRoute = (props) => {
const [authUser, setAuthUser] = useState({});
const [isReady, setIsReady] = useState(false);
useEffect(() => {
fetchAuthenticatedUser({ forceRefresh: !!getAuthenticatedUser() }).then((authenticatedUser) => {
setAuthUser(authenticatedUser);
setIsReady(true);
});
}, []);
if (isReady) {
if (authUser && authUser.username) {
global.location.href = getConfig().LMS_BASE_URL.concat(DEFAULT_REDIRECT_URL);
return null;
}
return <Route {...props} />;
}
return null;
};
export default UnAuthOnlyRoute;