Skip to content

Commit 29f045b

Browse files
ymc9claude
andauthored
fix(orm): stricter validation in $setAuth and clean up imports (#2514)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c36cf8e commit 29f045b

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

packages/orm/src/client/client-impl.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,14 @@ import * as BuiltinFunctions from './functions';
4141
import { SchemaDbPusher } from './helpers/schema-db-pusher';
4242
import type { ClientOptions, ProceduresOptions } from './options';
4343
import type { AnyPlugin } from './plugin';
44+
import { createZenStackPromise, type ZenStackPromise } from './promise';
45+
import { fieldHasDefaultValue, getField, isUnsupportedField, requireModel } from './query-utils';
46+
import { ResultProcessor } from './result-processor';
4447

4548
type ExtResultFieldDef = {
4649
needs: Record<string, true>;
4750
compute: (data: Record<string, any>) => unknown;
4851
};
49-
import { getField } from './query-utils';
50-
import { createZenStackPromise, type ZenStackPromise } from './promise';
51-
import { fieldHasDefaultValue, isUnsupportedField, requireModel } from './query-utils';
52-
import { ResultProcessor } from './result-processor';
5352

5453
/**
5554
* ZenStack ORM client.
@@ -172,7 +171,8 @@ export class ClientImpl {
172171
if (modelDef.computedFields) {
173172
for (const fieldName of Object.keys(modelDef.computedFields)) {
174173
// check both uncapitalized (current) and original (backward compat) model name
175-
const modelConfig = computedFieldsConfig?.[lowerCaseFirst(modelName)] ?? computedFieldsConfig?.[modelName];
174+
const modelConfig =
175+
computedFieldsConfig?.[lowerCaseFirst(modelName)] ?? computedFieldsConfig?.[modelName];
176176
const fieldConfig = modelConfig?.[fieldName];
177177
// Check if the computed field has a configuration
178178
if (fieldConfig === null || fieldConfig === undefined) {
@@ -426,7 +426,7 @@ export class ClientImpl {
426426
}
427427

428428
$setAuth(auth: AuthType<SchemaDef> | undefined) {
429-
if (auth !== undefined && typeof auth !== 'object') {
429+
if (auth !== undefined && (typeof auth !== 'object' || auth === null || Array.isArray(auth))) {
430430
throw new Error('Invalid auth object');
431431
}
432432
const newClient = new ClientImpl(this.schema, this.$options, this);

packages/orm/src/client/contract.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,13 @@ export type ClientContract<
124124
$queryRawUnsafe<T = unknown>(query: string, ...values: any[]): ZenStackPromise<Schema, T>;
125125

126126
/**
127-
* The current user identity.
127+
* The current user identity. If the client is not bound to any user context, returns `undefined`.
128128
*/
129129
get $auth(): AuthType<Schema> | undefined;
130130

131131
/**
132132
* Returns a new client bound to the specified user identity. The original client remains unchanged.
133+
* Pass `undefined` to return a client without any user context.
133134
*
134135
* @example
135136
* ```

0 commit comments

Comments
 (0)