Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const AppendInitScreen = () => {
getConnectService().setInvitation(invitationToken);
}

const res = await getConnectService().appendInit(ac);
const res = await getConnectService().appendInit(ac, config.situation);
if (res.err) {
if (res.val.type === ConnectErrorType.Cancel) {
return;
Expand All @@ -107,7 +107,13 @@ const AppendInitScreen = () => {
return handleSituation(AppendSituationCode.CtApiNotAvailablePreAuthenticator);
}

const startAppendRes = await getConnectService().startAppend(appendToken, loadedMs, ac);
const startAppendRes = await getConnectService().startAppend(
appendToken,
loadedMs,
ac,
undefined,
config.situation,
);
if (startAppendRes.err) {
if (startAppendRes.val.type === ConnectErrorType.Cancel) {
return;
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/connect/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type CorbadoConnectAppendConfig = {
onError?(error: string): void;
onSkip(status: AppendStatus): Promise<void>;
onComplete(status: AppendStatus, clientState: string): Promise<void>;
situation?: string;
};

export type AppendStatus = 'skip-implicit' | 'skip-explicit' | 'complete' | 'complete-noop';
Expand Down
15 changes: 11 additions & 4 deletions packages/web-core/src/services/ConnectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@ export class ConnectService {
return loginFinishResp;
}

async appendInit(abortController: AbortController): Promise<Result<ConnectAppendInitData, ConnectError>> {
async appendInit(
abortController: AbortController,
situation?: string,
): Promise<Result<ConnectAppendInitData, ConnectError>> {
const existingProcess = ConnectProcess.loadFromStorage(this.#projectId);
if (existingProcess) {
log.debug('process exists, preparing api clients');
Expand All @@ -363,7 +366,10 @@ export class ConnectService {
}
}

const { req, flags } = await this.#getInitReq();
const { req, flags } = await this.#getInitReq<ConnectAppendInitReq>();
if (situation) {
req.situation = situation;
}
const res = await this.wrapWithErr(() =>
this.#connectApi.connectAppendInit(req, { signal: abortController.signal }),
);
Expand Down Expand Up @@ -419,15 +425,16 @@ export class ConnectService {
loadedMs: number,
abortController?: AbortController,
initiatedByUser?: boolean,
situation?: string,
): Promise<Result<ConnectAppendStartRsp, ConnectError>> {
const existingProcess = await this.#getExistingProcess(() => this.appendInit(new AbortController()));
const existingProcess = await this.#getExistingProcess(() => this.appendInit(new AbortController(), situation));
if (!existingProcess) {
return Err(new ConnectError(ConnectErrorType.MissingInit));
}

return this.wrapWithErr(() =>
this.#connectApi.connectAppendStart(
{ appendTokenValue: appendTokenValue, forcePasskeyAppend: initiatedByUser, loadedMs },
{ appendTokenValue, forcePasskeyAppend: initiatedByUser, loadedMs, situation },
abortController && { signal: abortController.signal },
),
);
Expand Down
Loading