File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
tests/integration/tests/enhancements/with-policy Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -505,4 +505,33 @@ describe('With Policy: auth() test', () => {
505505 ] )
506506 ) ;
507507 } ) ;
508+
509+ it ( 'Default auth() without user context' , async ( ) => {
510+ const { enhance } = await loadSchema (
511+ `
512+ model User {
513+ id String @id
514+ posts Post[]
515+
516+ @@allow('all', true)
517+ }
518+
519+ model Post {
520+ id String @id @default(uuid())
521+ title String
522+ author User @relation(fields: [authorId], references: [id])
523+ authorId String @default(auth().id)
524+
525+ @@allow('all', auth().id != null)
526+ }
527+ `
528+ ) ;
529+
530+ const db = enhance ( ) ;
531+ await expect ( db . user . create ( { data : { id : 'userId-1' } } ) ) . toResolveTruthy ( ) ;
532+ await expect ( db . post . create ( { data : { title : 'title' } } ) ) . rejects . toThrow (
533+ 'Using `auth()` in `@default` requires a user context'
534+ ) ;
535+ await expect ( db . post . findMany ( { } ) ) . toResolveTruthy ( ) ;
536+ } ) ;
508537} ) ;
You can’t perform that action at this time.
0 commit comments