Skip to content

Commit bc4a368

Browse files
cpb8010Copilot
andauthored
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent c2102f4 commit bc4a368

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

packages/auth-server/pages/dashboard/sessions.vue

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,12 @@ const convertSessionSpec = (wasmSpec: WasmSessionSpec): SessionSpec => {
105105
else if (limit.limitType === "Lifetime") limitType = LimitType.Lifetime;
106106
else if (limit.limitType === "Allowance") limitType = LimitType.Allowance;
107107
else {
108-
const numericLimitType = Number(limit.limitType);
109-
if (Number.isNaN(numericLimitType)) {
110-
// eslint-disable-next-line no-console
111-
console.warn(
112-
"Unexpected limitType value received from WASM:",
113-
limit.limitType,
114-
);
115-
// Fallback to a safe default to avoid propagating an invalid enum value
116-
limitType = LimitType.Unlimited;
117-
} else {
118-
limitType = numericLimitType as LimitType;
119-
}
108+
const error = new Error(
109+
`Unexpected limitType value received from WASM: ${limit.limitType}`,
110+
);
111+
// eslint-disable-next-line no-console
112+
console.error(error);
113+
throw error;
120114
}
121115
122116
// Validate and convert BigInt values with try-catch
@@ -193,13 +187,20 @@ const {
193187
if (address.value === null) {
194188
throw new Error("Account address is null");
195189
}
190+
191+
// Ensure entryPoint is provided by the chain configuration
192+
const { entryPoint } = contracts as { entryPoint?: Address };
193+
if (!entryPoint) {
194+
throw new Error(`EntryPoint address is not configured for chain ${defaultChain.id}`);
195+
}
196+
196197
// Use the new listActiveSessions function from the SDK
197198
const { sessions: activeSessions } = await listActiveSessions({
198199
account: address.value,
199200
rpcUrl,
200201
contracts: {
201202
sessionValidator: contracts.sessionValidator,
202-
entryPoint: (contracts as { entryPoint?: Address }).entryPoint || "0x4337084D9E255Ff0702461CF8895CE9E3b5Ff108",
203+
entryPoint: entryPoint as Address,
203204
accountFactory: contracts.factory,
204205
webauthnValidator: contracts.webauthnValidator,
205206
eoaValidator: contracts.eoaValidator,

packages/sdk-4337/src/client/actions/sessions.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,19 @@ export async function listActiveSessions(
583583
contractsJson,
584584
);
585585

586-
// Parse the JSON result
587-
const sessions = JSON.parse(resultJson as string);
586+
// Parse the JSON result with basic validation
587+
let parsedSessions: unknown;
588+
try {
589+
parsedSessions = JSON.parse(resultJson as string);
590+
} catch (error) {
591+
throw new Error("Failed to parse sessions JSON returned from WASM");
592+
}
593+
594+
if (!Array.isArray(parsedSessions)) {
595+
throw new Error("Invalid sessions format returned from WASM: expected an array");
596+
}
588597

598+
const sessions = parsedSessions;
589599
return {
590600
sessions,
591601
};

0 commit comments

Comments
 (0)