mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-09-27 01:45:32 +00:00
fix(ui): redirect to sign-in when user is not authorized (#8512)
This commit is contained in:
parent
f4cc2b57a7
commit
60a97ea8bc
@ -23,6 +23,7 @@ import SlackChat from '../components/SlackChat/SlackChat';
|
|||||||
import { ROUTES } from '../constants/constants';
|
import { ROUTES } from '../constants/constants';
|
||||||
import { AuthTypes } from '../enums/signin.enum';
|
import { AuthTypes } from '../enums/signin.enum';
|
||||||
import AccountActivationConfirmation from '../pages/signup/account-activation-confirmation.component';
|
import AccountActivationConfirmation from '../pages/signup/account-activation-confirmation.component';
|
||||||
|
import { isProtectedRoute } from '../utils/AuthProvider.util';
|
||||||
import withSuspenseFallback from './withSuspenseFallback';
|
import withSuspenseFallback from './withSuspenseFallback';
|
||||||
|
|
||||||
const AuthenticatedAppRouter = withSuspenseFallback(
|
const AuthenticatedAppRouter = withSuspenseFallback(
|
||||||
@ -55,7 +56,6 @@ const AppRouter = () => {
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
authConfig,
|
authConfig,
|
||||||
isAuthDisabled,
|
|
||||||
isAuthenticated,
|
isAuthenticated,
|
||||||
loading,
|
loading,
|
||||||
isSigningIn,
|
isSigningIn,
|
||||||
@ -72,6 +72,11 @@ const AppRouter = () => {
|
|||||||
const isOidcProvider =
|
const isOidcProvider =
|
||||||
authConfig?.provider && oidcProviders.includes(authConfig.provider);
|
authConfig?.provider && oidcProviders.includes(authConfig.provider);
|
||||||
|
|
||||||
|
const isBasicAuthProvider =
|
||||||
|
authConfig &&
|
||||||
|
(authConfig.provider === AuthTypes.BASIC ||
|
||||||
|
authConfig.provider === AuthTypes.LDAP);
|
||||||
|
|
||||||
const fetchSlackChatConfig = () => {
|
const fetchSlackChatConfig = () => {
|
||||||
fetchSlackConfig()
|
fetchSlackConfig()
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
@ -114,95 +119,60 @@ const AppRouter = () => {
|
|||||||
}
|
}
|
||||||
}, [location.pathname]);
|
}, [location.pathname]);
|
||||||
|
|
||||||
return loading ? (
|
if (loading) {
|
||||||
<Loader />
|
return <Loader />;
|
||||||
) : (
|
}
|
||||||
<>
|
|
||||||
{isOidcProvider || isAuthenticated ? (
|
|
||||||
<>
|
|
||||||
<AuthenticatedAppRouter />
|
|
||||||
{slackChat}
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
{slackChat}
|
|
||||||
<Switch>
|
|
||||||
<Route exact component={BasicSignupPage} path={ROUTES.REGISTER} />
|
|
||||||
|
|
||||||
{callbackComponent ? (
|
if (!isAuthenticated && isProtectedRoute(location.pathname)) {
|
||||||
<Route component={callbackComponent} path={ROUTES.CALLBACK} />
|
return <Redirect to={ROUTES.SIGNIN} />;
|
||||||
) : null}
|
}
|
||||||
<Route exact path={ROUTES.HOME}>
|
|
||||||
{!isAuthDisabled && !isAuthenticated && !isSigningIn ? (
|
if (isOidcProvider || isAuthenticated) {
|
||||||
<>
|
return (
|
||||||
<Redirect to={ROUTES.SIGNIN} />
|
<>
|
||||||
<Route
|
<AuthenticatedAppRouter />
|
||||||
exact
|
{slackChat}
|
||||||
component={ForgotPassword}
|
</>
|
||||||
path={ROUTES.FORGOT_PASSWORD}
|
);
|
||||||
/>
|
}
|
||||||
<Route
|
|
||||||
exact
|
return (
|
||||||
component={ResetPassword}
|
<Switch>
|
||||||
path={ROUTES.RESET_PASSWORD}
|
{slackChat}
|
||||||
/>
|
<Route exact component={SigninPage} path={ROUTES.SIGNIN} />
|
||||||
<Route
|
{callbackComponent ? (
|
||||||
exact
|
<Route component={callbackComponent} path={ROUTES.CALLBACK} />
|
||||||
component={AccountActivationConfirmation}
|
) : null}
|
||||||
path={ROUTES.ACCOUNT_ACTIVATION}
|
|
||||||
/>
|
<Route exact path={ROUTES.HOME}>
|
||||||
</>
|
{!isAuthenticated && !isSigningIn ? (
|
||||||
) : (
|
<>
|
||||||
<Redirect to={ROUTES.MY_DATA} />
|
<Redirect to={ROUTES.SIGNIN} />
|
||||||
)}
|
</>
|
||||||
</Route>
|
) : (
|
||||||
{!isSigningIn ? (
|
<Redirect to={ROUTES.MY_DATA} />
|
||||||
<>
|
)}
|
||||||
<Route exact component={SigninPage} path={ROUTES.SIGNIN} />
|
</Route>
|
||||||
<Route
|
|
||||||
exact
|
{isBasicAuthProvider && (
|
||||||
component={ForgotPassword}
|
<>
|
||||||
path={ROUTES.FORGOT_PASSWORD}
|
<Route exact component={BasicSignupPage} path={ROUTES.REGISTER} />
|
||||||
/>
|
<Route
|
||||||
<Route
|
exact
|
||||||
exact
|
component={ForgotPassword}
|
||||||
component={ResetPassword}
|
path={ROUTES.FORGOT_PASSWORD}
|
||||||
path={ROUTES.RESET_PASSWORD}
|
/>
|
||||||
/>
|
<Route exact component={ResetPassword} path={ROUTES.RESET_PASSWORD} />
|
||||||
<Route
|
<Route
|
||||||
exact
|
exact
|
||||||
component={AccountActivationConfirmation}
|
component={AccountActivationConfirmation}
|
||||||
path={ROUTES.ACCOUNT_ACTIVATION}
|
path={ROUTES.ACCOUNT_ACTIVATION}
|
||||||
/>
|
/>
|
||||||
</>
|
|
||||||
) : null}
|
|
||||||
{isAuthDisabled || isAuthenticated ? (
|
|
||||||
<AuthenticatedAppRouter />
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<Redirect to={ROUTES.SIGNIN} />
|
|
||||||
<Route
|
|
||||||
exact
|
|
||||||
component={ForgotPassword}
|
|
||||||
path={ROUTES.FORGOT_PASSWORD}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
exact
|
|
||||||
component={ResetPassword}
|
|
||||||
path={ROUTES.RESET_PASSWORD}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
exact
|
|
||||||
component={AccountActivationConfirmation}
|
|
||||||
path={ROUTES.ACCOUNT_ACTIVATION}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
<Route exact component={PageNotFound} path={ROUTES.NOT_FOUND} />
|
|
||||||
</Switch>
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</>
|
{isAuthenticated && <AuthenticatedAppRouter />}
|
||||||
|
<Route exact component={PageNotFound} path={ROUTES.NOT_FOUND} />
|
||||||
|
</Switch>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user