Skip to content

Commit 2b5b4a2

Browse files
committed
Server side session
1 parent 1b5bf1c commit 2b5b4a2

9 files changed

Lines changed: 175 additions & 62 deletions

File tree

packages/shared-ui/src/flowHandler/blocks/EmailVerifyBlock.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export class EmailVerifyBlock extends Block<BlockDataEmailVerify> {
1919
readonly type = BlockTypes.EmailVerify;
2020
readonly initialScreen;
2121
readonly authType: AuthType;
22-
readonly isNewDevice: boolean;
2322
readonly emailLinkToken?: string;
2423

2524
constructor(
@@ -30,7 +29,6 @@ export class EmailVerifyBlock extends Block<BlockDataEmailVerify> {
3029
data: GeneralBlockVerifyIdentifier,
3130
authType: AuthType,
3231
fromEmailVerifyFromUrl: boolean,
33-
isNewDevice: boolean,
3432
emailLinkToken?: string,
3533
) {
3634
super(app, flowHandler, common, errorTranslator);
@@ -51,7 +49,6 @@ export class EmailVerifyBlock extends Block<BlockDataEmailVerify> {
5149
}
5250

5351
this.authType = authType;
54-
this.isNewDevice = isNewDevice;
5552
this.emailLinkToken = emailLinkToken;
5653

5754
this.data = {
@@ -71,7 +68,7 @@ export class EmailVerifyBlock extends Block<BlockDataEmailVerify> {
7168
data: GeneralBlockVerifyIdentifier,
7269
authType: AuthType,
7370
): EmailVerifyBlock {
74-
return new EmailVerifyBlock(app, flowHandler, common, translator, data, authType, false, false);
71+
return new EmailVerifyBlock(app, flowHandler, common, translator, data, authType, false);
7572
}
7673

7774
static fromUrl(
@@ -80,7 +77,6 @@ export class EmailVerifyBlock extends Block<BlockDataEmailVerify> {
8077
translator: ErrorTranslator,
8178
data: GeneralBlockVerifyIdentifier,
8279
authType: AuthType,
83-
isNewDevice: boolean,
8480
emailLinkToken: string,
8581
): EmailVerifyBlock {
8682
const emptyCommon: ProcessCommon = {
@@ -90,17 +86,7 @@ export class EmailVerifyBlock extends Block<BlockDataEmailVerify> {
9086
environment: '',
9187
};
9288

93-
return new EmailVerifyBlock(
94-
app,
95-
flowHandler,
96-
emptyCommon,
97-
translator,
98-
data,
99-
authType,
100-
true,
101-
isNewDevice,
102-
emailLinkToken,
103-
);
89+
return new EmailVerifyBlock(app, flowHandler, emptyCommon, translator, data, authType, true, emailLinkToken);
10490
}
10591

10692
showEditEmail() {
@@ -163,11 +149,7 @@ export class EmailVerifyBlock extends Block<BlockDataEmailVerify> {
163149
throw new Error('Email link token is missing');
164150
}
165151

166-
const res = await this.app.authProcessService.finishEmailLinkVerification(
167-
abortController,
168-
this.emailLinkToken,
169-
this.isNewDevice,
170-
);
152+
const res = await this.app.authProcessService.finishEmailLinkVerification(abortController, this.emailLinkToken);
171153

172154
this.updateProcess(res);
173155

packages/shared-ui/src/flowHandler/processHandler.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ export class ProcessHandler {
198198
this.#errorTranslator,
199199
emailVerifyFromUrl.data,
200200
emailVerifyFromUrl.authType,
201-
emailVerifyFromUrl.isNewDevice,
202201
emailVerifyFromUrl.token,
203202
) as Block<unknown>;
204203

packages/web-core/openapi/spec_v2.yaml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ tags:
3333
description: All API calls that are related to a connect process
3434

3535
paths:
36+
/v2/process-config:
37+
get:
38+
summary: Retrieve process configuration
39+
description: Retrieves the process configuration settings.
40+
operationId: GetProcessConfig
41+
tags:
42+
- Configs
43+
responses:
44+
"200":
45+
description: Process configuration settings.
46+
content:
47+
application/json:
48+
schema:
49+
$ref: "#/components/schemas/processConfigRsp"
50+
3651
/v2/session-config:
3752
get:
3853
summary: Retrieve session configuration
@@ -1169,16 +1184,13 @@ components:
11691184
- code
11701185
- identifierType
11711186
- verificationType
1172-
- isNewDevice
11731187
properties:
11741188
code:
11751189
type: string
11761190
identifierType:
11771191
$ref: "#/components/schemas/loginIdentifierType"
11781192
verificationType:
11791193
$ref: "#/components/schemas/verificationMethod"
1180-
isNewDevice:
1181-
type: boolean
11821194

11831195
socialVerifyStartReq:
11841196
type: object
@@ -1208,6 +1220,17 @@ components:
12081220
value:
12091221
type: string
12101222

1223+
processConfigRsp:
1224+
type: object
1225+
required:
1226+
- useServerSideProcessId
1227+
- frontendApiUrl
1228+
properties:
1229+
useServerSideProcessId:
1230+
type: boolean
1231+
frontendApiUrl:
1232+
type: string
1233+
12111234
sessionConfigRsp:
12121235
type: object
12131236
required:

packages/web-core/src/api/v2/api.ts

Lines changed: 86 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,12 +1408,6 @@ export interface IdentifierVerifyFinishReq {
14081408
* @memberof IdentifierVerifyFinishReq
14091409
*/
14101410
'verificationType': VerificationMethod;
1411-
/**
1412-
*
1413-
* @type {boolean}
1414-
* @memberof IdentifierVerifyFinishReq
1415-
*/
1416-
'isNewDevice': boolean;
14171411
}
14181412

14191413

@@ -2248,6 +2242,25 @@ export interface ProcessCommon {
22482242
*/
22492243
'environment': string;
22502244
}
2245+
/**
2246+
*
2247+
* @export
2248+
* @interface ProcessConfigRsp
2249+
*/
2250+
export interface ProcessConfigRsp {
2251+
/**
2252+
*
2253+
* @type {boolean}
2254+
* @memberof ProcessConfigRsp
2255+
*/
2256+
'useServerSideProcessId': boolean;
2257+
/**
2258+
*
2259+
* @type {string}
2260+
* @memberof ProcessConfigRsp
2261+
*/
2262+
'frontendApiUrl': string;
2263+
}
22512264
/**
22522265
* tbd.
22532266
* @export
@@ -4206,6 +4219,43 @@ export class AuthApi extends BaseAPI {
42064219
*/
42074220
export const ConfigsApiAxiosParamCreator = function (configuration?: Configuration) {
42084221
return {
4222+
/**
4223+
* Retrieves the process configuration settings.
4224+
* @summary Retrieve process configuration
4225+
* @param {*} [options] Override http request option.
4226+
* @throws {RequiredError}
4227+
*/
4228+
getProcessConfig: async (options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
4229+
const localVarPath = `/v2/process-config`;
4230+
// use dummy base URL string because the URL constructor only accepts absolute URLs.
4231+
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
4232+
let baseOptions;
4233+
if (configuration) {
4234+
baseOptions = configuration.baseOptions;
4235+
}
4236+
4237+
const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
4238+
const localVarHeaderParameter = {} as any;
4239+
const localVarQueryParameter = {} as any;
4240+
4241+
// authentication bearerAuth required
4242+
// http bearer authentication required
4243+
await setBearerAuthToObject(localVarHeaderParameter, configuration)
4244+
4245+
// authentication projectID required
4246+
await setApiKeyToObject(localVarHeaderParameter, "X-Corbado-ProjectID", configuration)
4247+
4248+
4249+
4250+
setSearchParams(localVarUrlObj, localVarQueryParameter);
4251+
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
4252+
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
4253+
4254+
return {
4255+
url: toPathString(localVarUrlObj),
4256+
options: localVarRequestOptions,
4257+
};
4258+
},
42094259
/**
42104260
* Retrieves the session configuration settings.
42114261
* @summary Retrieve session configuration
@@ -4290,6 +4340,16 @@ export const ConfigsApiAxiosParamCreator = function (configuration?: Configurati
42904340
export const ConfigsApiFp = function(configuration?: Configuration) {
42914341
const localVarAxiosParamCreator = ConfigsApiAxiosParamCreator(configuration)
42924342
return {
4343+
/**
4344+
* Retrieves the process configuration settings.
4345+
* @summary Retrieve process configuration
4346+
* @param {*} [options] Override http request option.
4347+
* @throws {RequiredError}
4348+
*/
4349+
async getProcessConfig(options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<ProcessConfigRsp>> {
4350+
const localVarAxiosArgs = await localVarAxiosParamCreator.getProcessConfig(options);
4351+
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
4352+
},
42934353
/**
42944354
* Retrieves the session configuration settings.
42954355
* @summary Retrieve session configuration
@@ -4320,6 +4380,15 @@ export const ConfigsApiFp = function(configuration?: Configuration) {
43204380
export const ConfigsApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
43214381
const localVarFp = ConfigsApiFp(configuration)
43224382
return {
4383+
/**
4384+
* Retrieves the process configuration settings.
4385+
* @summary Retrieve process configuration
4386+
* @param {*} [options] Override http request option.
4387+
* @throws {RequiredError}
4388+
*/
4389+
getProcessConfig(options?: any): AxiosPromise<ProcessConfigRsp> {
4390+
return localVarFp.getProcessConfig(options).then((request) => request(axios, basePath));
4391+
},
43234392
/**
43244393
* Retrieves the session configuration settings.
43254394
* @summary Retrieve session configuration
@@ -4348,6 +4417,17 @@ export const ConfigsApiFactory = function (configuration?: Configuration, basePa
43484417
* @extends {BaseAPI}
43494418
*/
43504419
export class ConfigsApi extends BaseAPI {
4420+
/**
4421+
* Retrieves the process configuration settings.
4422+
* @summary Retrieve process configuration
4423+
* @param {*} [options] Override http request option.
4424+
* @throws {RequiredError}
4425+
* @memberof ConfigsApi
4426+
*/
4427+
public getProcessConfig(options?: AxiosRequestConfig) {
4428+
return ConfigsApiFp(this.configuration).getProcessConfig(options).then((request) => request(this.axios, this.basePath));
4429+
}
4430+
43514431
/**
43524432
* Retrieves the session configuration settings.
43534433
* @summary Retrieve session configuration

packages/web-core/src/models/authProcess.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,21 @@ export class AuthProcess {
4747
localStorage.removeItem(getStorageKey(projectId));
4848
}
4949
}
50+
51+
export class TempAuthProcess {
52+
readonly id: string;
53+
readonly projectId: string;
54+
readonly frontendApiUrl: string;
55+
readonly expiresAt: number;
56+
57+
constructor(id: string, projectId: string, expiresAt: number, frontendApiUrl: string) {
58+
this.id = id;
59+
this.projectId = projectId;
60+
this.expiresAt = expiresAt;
61+
this.frontendApiUrl = frontendApiUrl;
62+
}
63+
64+
isValid(): boolean {
65+
return this.expiresAt > Date.now() / 1000;
66+
}
67+
}
Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { GeneralBlockVerifyIdentifier, VerificationMethod } from '../api';
2-
import { BlockType } from '../api';
3-
import { AuthType } from '../api';
4-
import { AuthProcess } from './authProcess';
2+
import { AuthType, BlockType } from '../api';
3+
import { TempAuthProcess } from './authProcess';
54

65
type EmailVerifyFromUrlData = {
76
blockData: {
@@ -12,7 +11,7 @@ type EmailVerifyFromUrlData = {
1211
};
1312
authType: number;
1413
process: {
15-
id: string;
14+
tempId: string;
1615
projectId: string;
1716
expires: number;
1817
frontendApiUrl: string;
@@ -22,26 +21,17 @@ type EmailVerifyFromUrlData = {
2221
export class EmailVerifyFromUrl {
2322
data: GeneralBlockVerifyIdentifier;
2423
token: string;
25-
isNewDevice: boolean;
26-
process: AuthProcess;
24+
process: TempAuthProcess;
2725
authType: AuthType;
2826

29-
constructor(
30-
data: GeneralBlockVerifyIdentifier,
31-
token: string,
32-
isNewDevice: boolean,
33-
process: AuthProcess,
34-
authType: AuthType,
35-
) {
27+
constructor(data: GeneralBlockVerifyIdentifier, token: string, process: TempAuthProcess, authType: AuthType) {
3628
this.data = data;
3729
this.token = token;
38-
this.isNewDevice = isNewDevice;
3930
this.process = process;
4031
this.authType = authType;
4132
}
4233

43-
static fromURL(encodedProcess: string, token: string, existingProcess: AuthProcess | undefined): EmailVerifyFromUrl {
44-
console.log('maybeProcess', encodedProcess, existingProcess);
34+
static fromURL(encodedProcess: string, token: string): EmailVerifyFromUrl {
4535
const decoded = JSON.parse(atob(encodedProcess)) as EmailVerifyFromUrlData;
4636
const process = decoded.process;
4737

@@ -54,16 +44,20 @@ export class EmailVerifyFromUrl {
5444
blockType: BlockType.EmailVerify,
5545
};
5646

57-
const isNewDevice = existingProcess?.id !== process.id;
5847
let authType: AuthType;
5948
if (decoded.authType === 0) {
6049
authType = AuthType.Login;
6150
} else {
6251
authType = AuthType.Signup;
6352
}
6453

65-
const authProcess = new AuthProcess(process.id, process.projectId, process.expires, process.frontendApiUrl);
54+
const tempAuthProcess = new TempAuthProcess(
55+
process.tempId,
56+
process.projectId,
57+
process.expires,
58+
process.frontendApiUrl,
59+
);
6660

67-
return new EmailVerifyFromUrl(data, token, isNewDevice, authProcess, authType);
61+
return new EmailVerifyFromUrl(data, token, tempAuthProcess, authType);
6862
}
6963
}

0 commit comments

Comments
 (0)