Skip to content

Commit 1c29f0b

Browse files
Merge pull request #395 from Web3Auth/feat/record-id
feat: generate record-id and include in login b64 params
2 parents c652f31 + ded4246 commit 1c29f0b

8 files changed

Lines changed: 88 additions & 70 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,6 @@ dist
105105

106106
.DS_Store
107107

108-
.rollup*
108+
.rollup*
109+
110+
.npmrc

examples/vue-example/package-lock.json

Lines changed: 58 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/vue-example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"bs58": "^6.0.0",
2020
"core-js": "^3.49.0",
2121
"viem": "^2.47.6",
22-
"vue": "^3.5.30"
22+
"vue": "^3.5.31"
2323
},
2424
"devDependencies": {
2525
"@tailwindcss/vite": "^4.2.2",

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
},
112112
"dependencies": {
113113
"@toruslabs/constants": "^16.1.1",
114-
"@toruslabs/customauth": "^22.3.2",
114+
"@toruslabs/customauth": "^22.3.3",
115115
"@toruslabs/ffjavascript": "^6.0.0",
116116
"@toruslabs/metadata-helpers": "^8.2.0",
117117
"@toruslabs/secure-pub-sub": "^4.3.0",

src/core/auth.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
BaseLoginParams,
2424
BUILD_ENV,
2525
DEFAULT_SESSION_TIME,
26+
generateRecordId,
2627
jsonToBase64,
2728
LoginParams,
2829
POPUP_TIMEOUT,
@@ -323,6 +324,7 @@ export class Auth {
323324
};
324325

325326
const loginId = StorageManager.generateRandomSessionKey();
327+
const recordId = generateRecordId();
326328

327329
const dataObject: AuthRequestPayload = {
328330
actionType: AUTH_ACTIONS.MANAGE_MFA,
@@ -342,7 +344,7 @@ export class Auth {
342344
extraLoginOptions: {
343345
login_hint: this.state.userInfo.userId,
344346
},
345-
appState: jsonToBase64({ loginId }),
347+
appState: jsonToBase64({ loginId, recordId }),
346348
},
347349
sessionId: this.sessionId,
348350
accessToken: await this.getAccessToken(),
@@ -351,6 +353,7 @@ export class Auth {
351353
this.storeAuthPayload(loginId, dataObject, dataObject.options.sessionTime, true);
352354
const configParams: BaseLoginParams = {
353355
loginId,
356+
recordId,
354357
sessionNamespace: this.options.sessionNamespace,
355358
storageServerUrl: this.options.storageServerUrl,
356359
};
@@ -528,9 +531,11 @@ export class Auth {
528531

529532
private async authHandler(url: string, dataObject: AuthRequestPayload, popupTimeout = 1000 * 10): Promise<AuthFlowResult | null> {
530533
const loginId = StorageManager.generateRandomSessionKey();
534+
const recordId = generateRecordId();
531535
await this.storeAuthPayload(loginId, dataObject);
532536
const configParams: BaseLoginParams = {
533537
loginId,
538+
recordId,
534539
sessionNamespace: this.options.sessionNamespace,
535540
storageServerUrl: this.options.storageServerUrl,
536541
};

src/utils/interfaces.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,11 @@ export interface BaseLoginParams {
539539
loginId?: string;
540540
sessionNamespace?: string;
541541
storageServerUrl?: string;
542+
543+
/**
544+
* Optional record id to be used for analytics purposes.
545+
*/
546+
recordId?: string;
542547
}
543548

544549
export interface AuthRequestPayload {

src/utils/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@ export function isObject(value: unknown): value is Record<PropertyKey, unknown>
3131
export function hasProperty<Key extends PropertyKey>(value: unknown, key: Key): value is Record<Key, unknown> {
3232
return isObject(value) && key in value;
3333
}
34+
35+
export function generateRecordId(): string {
36+
const cr = typeof globalThis === "object" ? globalThis.crypto : null;
37+
if (typeof cr?.randomUUID !== "function") throw new Error("crypto.randomUUID must be defined");
38+
return cr.randomUUID();
39+
}

0 commit comments

Comments
 (0)