Skip to content

Commit 30b4a4a

Browse files
committed
Use process-config endpoint (complete)
1 parent 781c282 commit 30b4a4a

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

packages/web-core/src/services/ProcessService.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type {
2121
GeneralBlockSignupInit,
2222
LoginIdentifier,
2323
PasskeyOperation,
24+
ProcessConfigRsp,
2425
ProcessInitReq,
2526
ProcessInitRsp,
2627
ProcessResponse,
@@ -29,6 +30,7 @@ import type {
2930
import {
3031
AuthApi,
3132
BlockType,
33+
ConfigsApi,
3234
LoginIdentifierType,
3335
PasskeyEventType,
3436
SocialDataStatusEnum,
@@ -48,6 +50,7 @@ const lastIdentifierKey = 'cbo_last_identifier';
4850

4951
export class ProcessService {
5052
#authApi: AuthApi = new AuthApi();
53+
#configApi: ConfigsApi = new ConfigsApi();
5154
#webAuthnService: WebAuthnService;
5255

5356
readonly #projectId: string;
@@ -87,6 +90,12 @@ export class ProcessService {
8790
// we check if there is a process in local storage, if not we have to create a new one
8891
const process = AuthProcess.loadFromStorage(this.#projectId);
8992
if (!process) {
93+
const processConfig = await this.#processConfig();
94+
if (processConfig.err) {
95+
return processConfig;
96+
}
97+
98+
this.#setApisV2Config(processConfig.val);
9099
console.log('process is missing');
91100
return this.#initNewAuthProcess(abortController, frontendPreferredBlockType);
92101
}
@@ -195,7 +204,6 @@ export class ProcessService {
195204
abortController: AbortController,
196205
frontendPreferredBlockType?: BlockType,
197206
): Promise<Result<ProcessResponse, CorbadoError>> {
198-
console.log('initNewAuthProcess');
199207
const res = await this.#initAuthProcess(abortController, frontendPreferredBlockType);
200208
if (res.err) {
201209
return res;
@@ -213,6 +221,18 @@ export class ProcessService {
213221
return Ok(res.val.processResponse);
214222
}
215223

224+
#setApisV2Config(config: ProcessConfigRsp): void {
225+
const frontendApiUrl = config.frontendApiUrl;
226+
const apiConfig = new Configuration({
227+
apiKey: this.#projectId,
228+
basePath: frontendApiUrl,
229+
});
230+
const axiosInstance = this.#createAxiosInstanceV2('', '');
231+
232+
this.#authApi = new AuthApi(apiConfig, frontendApiUrl, axiosInstance);
233+
this.#configApi = new ConfigsApi(apiConfig, frontendApiUrl, axiosInstance);
234+
}
235+
216236
#setApisV2(process?: AuthProcess): void {
217237
let frontendApiUrl = this.#getDefaultFrontendApiUrl();
218238
if (process?.frontendApiUrl && process?.frontendApiUrl.length > 0) {
@@ -226,6 +246,7 @@ export class ProcessService {
226246
const axiosInstance = this.#createAxiosInstanceV2(process?.id ?? '', '');
227247

228248
this.#authApi = new AuthApi(config, frontendApiUrl, axiosInstance);
249+
this.#configApi = new ConfigsApi(config, frontendApiUrl, axiosInstance);
229250
}
230251

231252
#setApisV2ByTempProcess(tempProcess: TempAuthProcess): void {
@@ -235,10 +256,10 @@ export class ProcessService {
235256
basePath: frontendApiUrl,
236257
});
237258

238-
console.log(`Setting up API with temp process: ${tempProcess.id} for project: ${tempProcess.projectId}`);
239259
const axiosInstance = this.#createAxiosInstanceV2('', tempProcess.id);
240260

241261
this.#authApi = new AuthApi(config, frontendApiUrl, axiosInstance);
262+
this.#configApi = new ConfigsApi(config, frontendApiUrl, axiosInstance);
242263
}
243264

244265
async #initAuthProcess(
@@ -277,6 +298,10 @@ export class ProcessService {
277298
}
278299
}
279300

301+
async #processConfig(): Promise<Result<ProcessConfigRsp, CorbadoError>> {
302+
return this.wrapWithErr(() => this.#configApi.getProcessConfig());
303+
}
304+
280305
async #processInit(
281306
abortController: AbortController,
282307
passkeyAppendShown: number | null,

0 commit comments

Comments
 (0)