@@ -12,6 +12,8 @@ import { AUTH_LOGIN_URL } from "constants/routesURL";
1212import { AuthSearchParams } from "constants/authConstants" ;
1313import { saveAuthSearchParams } from "pages/userAuth/authUtils" ;
1414import { Suspense , lazy } from "react" ;
15+ import Flex from "antd/es/flex" ;
16+ import { TacoButton } from "components/button" ;
1517
1618const AppView = lazy (
1719 ( ) => import ( './AppView' )
@@ -35,6 +37,8 @@ export interface AppViewInstanceOptions<I = any> {
3537 moduleInputs ?: I ;
3638}
3739
40+ let isAuthButtonClicked = false ;
41+
3842export class AppViewInstance < I = any , O = any > {
3943 private comp : RootComp | null = null ;
4044 private prevOutputs : any = null ;
@@ -44,6 +48,7 @@ export class AppViewInstance<I = any, O = any> {
4448 baseUrl : "https://api-service.lowcoder.cloud" ,
4549 webUrl : "https://app.lowcoder.cloud" ,
4650 } ;
51+ private authorizedUser : boolean = true ;
4752
4853 constructor ( private appId : string , private node : Element , private root : Root , options : AppViewInstanceOptions = { } ) {
4954 Object . assign ( this . options , options ) ;
@@ -81,7 +86,15 @@ export class AppViewInstance<I = any, O = any> {
8186 [ AuthSearchParams . redirectUrl ] : encodeURIComponent ( window . location . href ) ,
8287 [ AuthSearchParams . loginType ] : null ,
8388 } )
84- window . location . href = `${ webUrl } ${ AUTH_LOGIN_URL } ` ;
89+ // window.location.href = `${webUrl}${AUTH_LOGIN_URL}`;
90+ this . authorizedUser = false ;
91+ return {
92+ data : {
93+ orgCommonSettings : undefined ,
94+ applicationDSL : { } ,
95+ moduleDSL : { } ,
96+ }
97+ } ;
8598 }
8699 } ) ;
87100
@@ -143,18 +156,45 @@ export class AppViewInstance<I = any, O = any> {
143156 private async render ( ) {
144157 const data = await this . dataPromise ;
145158 this . root . render (
146- < StyleSheetManager target = { this . node as HTMLElement } >
147- < Suspense fallback = { null } >
148- < AppView
149- appId = { this . appId }
150- dsl = { data . appDsl }
151- moduleDsl = { data . moduleDslMap }
152- moduleInputs = { this . options . moduleInputs }
153- onCompChange = { ( comp ) => this . handleCompChange ( comp ) }
154- onModuleEventTriggered = { ( eventName ) => this . emit ( "moduleEventTriggered" , [ eventName ] ) }
155- />
156- </ Suspense >
157- </ StyleSheetManager >
159+ this . authorizedUser ? (
160+ < StyleSheetManager target = { this . node as HTMLElement } >
161+ < Suspense fallback = { null } >
162+ < AppView
163+ appId = { this . appId }
164+ dsl = { data . appDsl }
165+ moduleDsl = { data . moduleDslMap }
166+ moduleInputs = { this . options . moduleInputs }
167+ onCompChange = { ( comp ) => this . handleCompChange ( comp ) }
168+ onModuleEventTriggered = { ( eventName ) => this . emit ( "moduleEventTriggered" , [ eventName ] ) }
169+ />
170+ </ Suspense >
171+ </ StyleSheetManager >
172+ ) : (
173+ < Flex vertical = { true } align = "center" justify = "center" >
174+ < h4 > This resource needs authentication.</ h4 >
175+ { ! isAuthButtonClicked ? (
176+ < TacoButton
177+ buttonType = "primary"
178+ onClick = { ( ) => {
179+ isAuthButtonClicked = true ;
180+ window . open ( `${ this . options . webUrl } ${ AUTH_LOGIN_URL } ` , '_blank' ) ;
181+ this . render ( ) ;
182+ } }
183+ >
184+ Login
185+ </ TacoButton >
186+ ) : (
187+ < TacoButton
188+ buttonType = "primary"
189+ onClick = { ( ) => {
190+ window . location . reload ( ) ;
191+ } }
192+ >
193+ Refresh
194+ </ TacoButton >
195+ ) }
196+ </ Flex >
197+ )
158198 ) ;
159199 }
160200
0 commit comments