Skip to content

Commit

Permalink
feat: improve error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Azzerty23 committed Feb 20, 2024
1 parent dad65de commit edbe48a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/runtime/src/enhancements/default-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class DefaultAuthHandler extends DefaultPrismaProxyHandler {

private getDefaultValueFromAuth(fieldInfo: FieldInfo) {
if (!this.userContext) {
throw new Error(`Using \`auth()\` in \`@default\` requires a user context`);
throw new Error(`Default \`${fieldInfo.name}\` requires a user context`);
}
return fieldInfo.defaultValueProvider?.(this.userContext);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/tests/enhancements/with-policy/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,15 @@ describe('With Policy: auth() test', () => {
author User @relation(fields: [authorId], references: [id])
authorId String @default(auth().id)
@@allow('all', auth().id != null)
@@allow('all', true)
}
`
);

const db = enhance();
await expect(db.user.create({ data: { id: 'userId-1' } })).toResolveTruthy();
await expect(db.post.create({ data: { title: 'title' } })).rejects.toThrow(
'Using `auth()` in `@default` requires a user context'
`Default \`authorId\` requires a user context`
);
await expect(db.post.findMany({})).toResolveTruthy();
});
Expand Down

0 comments on commit edbe48a

Please sign in to comment.