Skip to content

Commit 5c94e81

Browse files
author
FalkWolsky
committed
Fixing App Redirection
1 parent 70b307b commit 5c94e81

File tree

1 file changed

+31
-15
lines changed
  • client/packages/lowcoder/src

1 file changed

+31
-15
lines changed

client/packages/lowcoder/src/app.tsx

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ type AppIndexProps = {
8484
getIsCommonSettingFetched: boolean;
8585
currentOrgId?: string;
8686
currentUserId: string;
87+
currentUserAnonymous: boolean;
8788
orgDev: boolean;
8889
defaultHomePage: string | null | undefined;
8990
fetchHomeDataFinished: boolean;
9091
fetchConfig: (orgId?: string) => void;
91-
fetchHomeData: () => void;
92+
fetchHomeData: (currentUserAnonymous?: boolean | undefined) => void;
9293
getCurrentUser: () => void;
9394
favicon: string;
9495
brandName: string;
@@ -98,7 +99,9 @@ type AppIndexProps = {
9899
class AppIndex extends React.Component<AppIndexProps, any> {
99100
componentDidMount() {
100101
this.props.getCurrentUser();
101-
this.props.fetchHomeData();
102+
if (!this.props.currentUserAnonymous) {
103+
this.props.fetchHomeData(this.props.currentUserAnonymous);
104+
}
102105
}
103106

104107
componentDidUpdate(prevProps: AppIndexProps) {
@@ -107,7 +110,9 @@ class AppIndex extends React.Component<AppIndexProps, any> {
107110
this.props.currentOrgId !== ''
108111
) {
109112
this.props.fetchConfig(this.props.currentOrgId);
110-
this.props.fetchHomeData();
113+
if (!this.props.currentUserAnonymous) {
114+
this.props.fetchHomeData(this.props.currentUserAnonymous);
115+
}
111116
}
112117
}
113118
render() {
@@ -123,7 +128,7 @@ class AppIndex extends React.Component<AppIndexProps, any> {
123128
}
124129

125130
// make sure all users in this app have checked login info
126-
if (!this.props.isFetchUserFinished || (this.props.currentUserId && !this.props.fetchHomeDataFinished)) {
131+
if (!this.props.isFetchUserFinished) { // || (this.props.currentUserId && !this.props.fetchHomeDataFinished)
127132
const hideLoadingHeader = isTemplate || isAuthUnRequired(pathname);
128133
return <ProductLoading hideHeader={hideLoadingHeader} />;
129134
}
@@ -280,16 +285,6 @@ class AppIndex extends React.Component<AppIndexProps, any> {
280285
<SystemWarning />
281286
<Router history={history}>
282287
<Switch>
283-
{this.props.isFetchUserFinished && this.props.defaultHomePage? (
284-
!this.props.orgDev ? (
285-
<Redirect exact from={BASE_URL} to={APPLICATION_VIEW_URL(this.props.defaultHomePage || "", "view")}/>
286-
) : (
287-
<Redirect exact from={BASE_URL} to={ORG_HOME_URL} />
288-
)
289-
) : (
290-
<Redirect exact from={BASE_URL} to={ALL_APPLICATIONS_URL} />
291-
)}
292-
293288
<LazyRoute
294289
exact
295290
path={IMPORT_APP_FROM_TEMPLATE_URL}
@@ -351,7 +346,19 @@ class AppIndex extends React.Component<AppIndexProps, any> {
351346
path={`/playground/:name/:dsl`}
352347
component={LazyComponentPlayground}
353348
/>
349+
350+
{this.props.isFetchUserFinished && this.props.defaultHomePage? (
351+
!this.props.orgDev ? (
352+
<Redirect exact from={BASE_URL} to={APPLICATION_VIEW_URL(this.props.defaultHomePage || "", "view")}/>
353+
) : (
354+
<Redirect exact from={BASE_URL} to={ORG_HOME_URL} />
355+
)
356+
) : (
357+
<Redirect exact from={BASE_URL} to={ALL_APPLICATIONS_URL} />
358+
)}
359+
354360
<Redirect to={`${COMPONENT_DOC_URL}/input`} path="/components" />
361+
355362
{developEnv() && (
356363
<>
357364
<LazyRoute
@@ -379,6 +386,7 @@ const mapStateToProps = (state: AppState) => ({
379386
getIsCommonSettingFetched: getIsCommonSettingFetched(state),
380387
orgDev: state.ui.users.user.orgDev,
381388
currentUserId: state.ui.users.currentUser.id,
389+
currentUserAnonymous: state.ui.users.currentUser.name === "ANONYMOUS",
382390
currentOrgId: state.ui.users.user.currentOrgId,
383391
defaultHomePage: state.ui.application.homeOrg?.commonSettings.defaultHomePage,
384392
fetchHomeDataFinished: Boolean(state.ui.application.homeOrg?.commonSettings),
@@ -394,7 +402,15 @@ const mapDispatchToProps = (dispatch: any) => ({
394402
dispatch(fetchUserAction());
395403
},
396404
fetchConfig: (orgId?: string) => dispatch(fetchConfigAction(orgId)),
397-
fetchHomeData: () => dispatch(fetchHomeData({}))
405+
fetchHomeData: (currentUserAnonymous: boolean | undefined) => {
406+
// the rule should be that if the user is not logged in and if he want to view an App, we should not fetch the home data
407+
if (window.location.pathname == APP_EDITOR_URL && !currentUserAnonymous && !currentUserAnonymous === undefined) {
408+
dispatch(fetchHomeData({}));
409+
}
410+
else {
411+
dispatch(fetchHomeData({}));
412+
}
413+
}
398414
});
399415

400416
const AppIndexWithProps = connect(mapStateToProps, mapDispatchToProps)(AppIndex);

0 commit comments

Comments
 (0)