Skip to content

Fix bundling issues + Add authentication for embedded app #847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
show authentication message instead of redirect of unauthorized users
  • Loading branch information
raheeliftikhar5 committed May 2, 2024
commit 7584d20a8c9447c430d2d5113713e7c9f1443432
66 changes: 53 additions & 13 deletions client/packages/lowcoder/src/appView/AppViewInstance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { AUTH_LOGIN_URL } from "constants/routesURL";
import { AuthSearchParams } from "constants/authConstants";
import { saveAuthSearchParams } from "pages/userAuth/authUtils";
import { Suspense, lazy } from "react";
import Flex from "antd/es/flex";
import { TacoButton } from "components/button";

const AppView = lazy(
() => import('./AppView')
Expand All @@ -35,6 +37,8 @@ export interface AppViewInstanceOptions<I = any> {
moduleInputs?: I;
}

let isAuthButtonClicked = false;

export class AppViewInstance<I = any, O = any> {
private comp: RootComp | null = null;
private prevOutputs: any = null;
Expand All @@ -44,6 +48,7 @@ export class AppViewInstance<I = any, O = any> {
baseUrl: "https://api-service.lowcoder.cloud",
webUrl: "https://app.lowcoder.cloud",
};
private authorizedUser: boolean = true;

constructor(private appId: string, private node: Element, private root: Root, options: AppViewInstanceOptions = {}) {
Object.assign(this.options, options);
Expand Down Expand Up @@ -81,7 +86,15 @@ export class AppViewInstance<I = any, O = any> {
[AuthSearchParams.redirectUrl]: encodeURIComponent(window.location.href),
[AuthSearchParams.loginType]: null,
})
window.location.href = `${webUrl}${AUTH_LOGIN_URL}`;
// window.location.href = `${webUrl}${AUTH_LOGIN_URL}`;
this.authorizedUser = false;
return {
data: {
orgCommonSettings: undefined,
applicationDSL: {},
moduleDSL: {},
}
};
}
});

Expand Down Expand Up @@ -143,18 +156,45 @@ export class AppViewInstance<I = any, O = any> {
private async render() {
const data = await this.dataPromise;
this.root.render(
<StyleSheetManager target={this.node as HTMLElement}>
<Suspense fallback={null}>
<AppView
appId={this.appId}
dsl={data.appDsl}
moduleDsl={data.moduleDslMap}
moduleInputs={this.options.moduleInputs}
onCompChange={(comp) => this.handleCompChange(comp)}
onModuleEventTriggered={(eventName) => this.emit("moduleEventTriggered", [eventName])}
/>
</Suspense>
</StyleSheetManager>
this.authorizedUser ? (
<StyleSheetManager target={this.node as HTMLElement}>
<Suspense fallback={null}>
<AppView
appId={this.appId}
dsl={data.appDsl}
moduleDsl={data.moduleDslMap}
moduleInputs={this.options.moduleInputs}
onCompChange={(comp) => this.handleCompChange(comp)}
onModuleEventTriggered={(eventName) => this.emit("moduleEventTriggered", [eventName])}
/>
</Suspense>
</StyleSheetManager>
) : (
<Flex vertical={true} align="center" justify="center">
<h4>This resource needs authentication.</h4>
{!isAuthButtonClicked ? (
<TacoButton
buttonType="primary"
onClick={() => {
isAuthButtonClicked = true;
window.open(`${this.options.webUrl}${AUTH_LOGIN_URL}`, '_blank');
this.render();
}}
>
Login
</TacoButton>
) : (
<TacoButton
buttonType="primary"
onClick={() => {
window.location.reload();
}}
>
Refresh
</TacoButton>
)}
</Flex>
)
);
}

Expand Down
Loading