diff --git a/packages/orm/src/client/client-impl.ts b/packages/orm/src/client/client-impl.ts index 97d812af0..cabc8bb41 100644 --- a/packages/orm/src/client/client-impl.ts +++ b/packages/orm/src/client/client-impl.ts @@ -41,15 +41,14 @@ import * as BuiltinFunctions from './functions'; import { SchemaDbPusher } from './helpers/schema-db-pusher'; import type { ClientOptions, ProceduresOptions } from './options'; import type { AnyPlugin } from './plugin'; +import { createZenStackPromise, type ZenStackPromise } from './promise'; +import { fieldHasDefaultValue, getField, isUnsupportedField, requireModel } from './query-utils'; +import { ResultProcessor } from './result-processor'; type ExtResultFieldDef = { needs: Record; compute: (data: Record) => unknown; }; -import { getField } from './query-utils'; -import { createZenStackPromise, type ZenStackPromise } from './promise'; -import { fieldHasDefaultValue, isUnsupportedField, requireModel } from './query-utils'; -import { ResultProcessor } from './result-processor'; /** * ZenStack ORM client. @@ -172,7 +171,8 @@ export class ClientImpl { if (modelDef.computedFields) { for (const fieldName of Object.keys(modelDef.computedFields)) { // check both uncapitalized (current) and original (backward compat) model name - const modelConfig = computedFieldsConfig?.[lowerCaseFirst(modelName)] ?? computedFieldsConfig?.[modelName]; + const modelConfig = + computedFieldsConfig?.[lowerCaseFirst(modelName)] ?? computedFieldsConfig?.[modelName]; const fieldConfig = modelConfig?.[fieldName]; // Check if the computed field has a configuration if (fieldConfig === null || fieldConfig === undefined) { @@ -426,7 +426,7 @@ export class ClientImpl { } $setAuth(auth: AuthType | undefined) { - if (auth !== undefined && typeof auth !== 'object') { + if (auth !== undefined && (typeof auth !== 'object' || auth === null || Array.isArray(auth))) { throw new Error('Invalid auth object'); } const newClient = new ClientImpl(this.schema, this.$options, this); diff --git a/packages/orm/src/client/contract.ts b/packages/orm/src/client/contract.ts index 0ed8d0004..4a451e203 100644 --- a/packages/orm/src/client/contract.ts +++ b/packages/orm/src/client/contract.ts @@ -124,12 +124,13 @@ export type ClientContract< $queryRawUnsafe(query: string, ...values: any[]): ZenStackPromise; /** - * The current user identity. + * The current user identity. If the client is not bound to any user context, returns `undefined`. */ get $auth(): AuthType | undefined; /** * Returns a new client bound to the specified user identity. The original client remains unchanged. + * Pass `undefined` to return a client without any user context. * * @example * ```