File tree Expand file tree Collapse file tree 7 files changed +73
-0
lines changed Expand file tree Collapse file tree 7 files changed +73
-0
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,8 @@ abstract class AsgardeoJavaScriptClient<T = Config> implements AsgardeoClient<T>
37
37
38
38
abstract initialize ( config : T , storage ?: Storage ) : Promise < boolean > ;
39
39
40
+ abstract reInitialize ( config : Partial < T > ) : Promise < boolean > ;
41
+
40
42
abstract getUser ( options ?: any ) : Promise < User > ;
41
43
42
44
abstract getAllOrganizations ( options ?: any , sessionId ?: string ) : Promise < AllOrganizationsApiResponse > ;
Original file line number Diff line number Diff line change @@ -97,6 +97,17 @@ export interface AsgardeoClient<T> {
97
97
*/
98
98
initialize ( config : T , storage ?: Storage ) : Promise < boolean > ;
99
99
100
+ /**
101
+ * Re-initializes the client with a new configuration.
102
+ *
103
+ * @remarks
104
+ * This can be partial configuration to update only specific fields.
105
+ *
106
+ * @param config - New configuration to re-initialize the client with.
107
+ * @returns Promise resolving to boolean indicating success.
108
+ */
109
+ reInitialize ( config : Partial < T > ) : Promise < boolean > ;
110
+
100
111
/**
101
112
* Checks if the client is currently loading.
102
113
* This can be used to determine if the client is in the process of initializing or fetching user data.
Original file line number Diff line number Diff line change @@ -145,6 +145,25 @@ class AsgardeoNextClient<T extends AsgardeoNextConfig = AsgardeoNextConfig> exte
145
145
) ;
146
146
}
147
147
148
+ override async reInitialize ( config : Partial < T > ) : Promise < boolean > {
149
+ let isInitialized : boolean = false ;
150
+
151
+ try {
152
+ await this . asgardeo . reInitialize ( config as any ) ;
153
+
154
+ isInitialized = true ;
155
+ } catch ( error ) {
156
+ throw new AsgardeoRuntimeError (
157
+ `Failed to re-initialize the client: ${ error instanceof Error ? error . message : String ( error ) } ` ,
158
+ 'AsgardeoNextClient-reInitialize-RuntimeError-001' ,
159
+ 'nextjs' ,
160
+ 'An error occurred while re-initializing the client. Please check your configuration and network connection.' ,
161
+ ) ;
162
+ }
163
+
164
+ return isInitialized ;
165
+ }
166
+
148
167
override async getUser ( userId ?: string ) : Promise < User > {
149
168
await this . ensureInitialized ( ) ;
150
169
const resolvedSessionId : string = userId || ( ( await getSessionId ( ) ) as string ) ;
Original file line number Diff line number Diff line change 19
19
import { TokenExchangeRequestConfig } from '@asgardeo/node' ;
20
20
import AsgardeoNextClient from '../AsgardeoNextClient' ;
21
21
import getSessionIdAction from './actions/getSessionId' ;
22
+ import { AsgardeoNextConfig } from '../models/config' ;
22
23
23
24
const asgardeo = async ( ) => {
24
25
const getAccessToken = async ( sessionId : string ) => {
@@ -35,10 +36,16 @@ const asgardeo = async () => {
35
36
return await client . exchangeToken ( config , sessionId ) ;
36
37
} ;
37
38
39
+ const reInitialize = async ( config : Partial < AsgardeoNextConfig > ) => {
40
+ const client : AsgardeoNextClient = AsgardeoNextClient . getInstance ( ) ;
41
+ return await client . reInitialize ( config ) ;
42
+ } ;
43
+
38
44
return {
39
45
getAccessToken,
40
46
getSessionId,
41
47
exchangeToken,
48
+ reInitialize,
42
49
} ;
43
50
} ;
44
51
Original file line number Diff line number Diff line change @@ -106,6 +106,27 @@ class AsgardeoReactClient<T extends AsgardeoReactConfig = AsgardeoReactConfig> e
106
106
} ) ;
107
107
}
108
108
109
+ override reInitialize ( config : Partial < AsgardeoReactConfig > ) : Promise < boolean > {
110
+ return this . withLoading ( async ( ) => {
111
+ let isInitialized : boolean ;
112
+
113
+ try {
114
+ await this . asgardeo . reInitialize ( config ) ;
115
+
116
+ isInitialized = true ;
117
+ } catch ( error ) {
118
+ throw new AsgardeoRuntimeError (
119
+ `Failed to check if the client is initialized: ${ error instanceof Error ? error . message : String ( error ) } ` ,
120
+ 'AsgardeoReactClient-reInitialize-RuntimeError-001' ,
121
+ 'react' ,
122
+ 'An error occurred while checking the initialization status of the client.' ,
123
+ ) ;
124
+ }
125
+
126
+ return isInitialized ;
127
+ } ) ;
128
+ }
129
+
109
130
override async updateUserProfile ( payload : any , userId ?: string ) : Promise < User > {
110
131
throw new Error ( 'Not implemented' ) ;
111
132
}
Original file line number Diff line number Diff line change @@ -121,6 +121,17 @@ export type AsgardeoContextProps = {
121
121
* @returns A promise that resolves to the token response or the raw response.
122
122
*/
123
123
exchangeToken : ( config : TokenExchangeRequestConfig ) => Promise < TokenResponse | Response > ;
124
+
125
+ /**
126
+ * Re-initializes the client with a new configuration.
127
+ *
128
+ * @remarks
129
+ * This can be partial configuration to update only specific fields.
130
+ *
131
+ * @param config - New configuration to re-initialize the client with.
132
+ * @returns Promise resolving to boolean indicating success.
133
+ */
134
+ reInitialize : ( config : Partial < AsgardeoReactConfig > ) => Promise < boolean > ;
124
135
} & Pick < AsgardeoReactConfig , 'storage' > ;
125
136
126
137
/**
@@ -151,6 +162,7 @@ const AsgardeoContext: Context<AsgardeoContextProps | null> = createContext<null
151
162
getAccessToken : null ,
152
163
exchangeToken : null ,
153
164
storage : 'sessionStorage' ,
165
+ reInitialize : null ,
154
166
} ) ;
155
167
156
168
AsgardeoContext . displayName = 'AsgardeoContext' ;
Original file line number Diff line number Diff line change @@ -430,6 +430,7 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
430
430
request : asgardeo . request . bind ( asgardeo ) ,
431
431
requestAll : asgardeo . requestAll . bind ( asgardeo ) ,
432
432
} ,
433
+ reInitialize : asgardeo . reInitialize . bind ( asgardeo ) ,
433
434
signInOptions,
434
435
getDecodedIdToken : asgardeo . getDecodedIdToken . bind ( asgardeo ) ,
435
436
exchangeToken : asgardeo . exchangeToken . bind ( asgardeo ) ,
You can’t perform that action at this time.
0 commit comments