@@ -12,6 +12,8 @@ import { AUTH_LOGIN_URL } from "constants/routesURL";
12
12
import { AuthSearchParams } from "constants/authConstants" ;
13
13
import { saveAuthSearchParams } from "pages/userAuth/authUtils" ;
14
14
import { Suspense , lazy } from "react" ;
15
+ import Flex from "antd/es/flex" ;
16
+ import { TacoButton } from "components/button" ;
15
17
16
18
const AppView = lazy (
17
19
( ) => import ( './AppView' )
@@ -35,6 +37,8 @@ export interface AppViewInstanceOptions<I = any> {
35
37
moduleInputs ?: I ;
36
38
}
37
39
40
+ let isAuthButtonClicked = false ;
41
+
38
42
export class AppViewInstance < I = any , O = any > {
39
43
private comp : RootComp | null = null ;
40
44
private prevOutputs : any = null ;
@@ -44,6 +48,7 @@ export class AppViewInstance<I = any, O = any> {
44
48
baseUrl : "https://api-service.lowcoder.cloud" ,
45
49
webUrl : "https://app.lowcoder.cloud" ,
46
50
} ;
51
+ private authorizedUser : boolean = true ;
47
52
48
53
constructor ( private appId : string , private node : Element , private root : Root , options : AppViewInstanceOptions = { } ) {
49
54
Object . assign ( this . options , options ) ;
@@ -81,7 +86,15 @@ export class AppViewInstance<I = any, O = any> {
81
86
[ AuthSearchParams . redirectUrl ] : encodeURIComponent ( window . location . href ) ,
82
87
[ AuthSearchParams . loginType ] : null ,
83
88
} )
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
+ } ;
85
98
}
86
99
} ) ;
87
100
@@ -143,18 +156,45 @@ export class AppViewInstance<I = any, O = any> {
143
156
private async render ( ) {
144
157
const data = await this . dataPromise ;
145
158
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
+ )
158
198
) ;
159
199
}
160
200
0 commit comments