Skip to content

Commit 9bc5cd1

Browse files
authored
add missing auth rules to model snippets on data modeling pages (#7999)
1 parent 934d7a2 commit 9bc5cd1

File tree

2 files changed

+15
-17
lines changed
  • src/pages/[platform]/build-a-backend/data/data-modeling

2 files changed

+15
-17
lines changed

src/pages/[platform]/build-a-backend/data/data-modeling/add-fields/index.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ a.schema({
6464
}),
6565
content: a.string(),
6666
}),
67-
});
67+
}).authorization((allow) => allow.publicApiKey());
6868
```
6969

7070
**Explicit definition:** Specify the "Location" as `a.customType()` in your schema. To use the custom type, reference it through `a.ref()` in the respective field definitions.
@@ -84,7 +84,7 @@ a.schema({
8484
User: a.model({
8585
lastKnownLocation: a.ref('Location'),
8686
}),
87-
});
87+
}).authorization((allow) => allow.publicApiKey());
8888
```
8989

9090
<InlineFilter filters={["javascript", "angular", "react-native", "react", "nextjs", "vue", "android", "flutter"]}>
@@ -131,7 +131,7 @@ a.schema({
131131
privacySetting: a.enum(['PRIVATE', 'FRIENDS_ONLY', 'PUBLIC']),
132132
content: a.string(),
133133
}),
134-
});
134+
}).authorization((allow) => allow.publicApiKey());
135135
```
136136

137137
Long-form approach
@@ -152,7 +152,7 @@ a.schema({
152152
Video: a.model({
153153
privacySetting: a.ref('PrivacySetting'),
154154
}),
155-
});
155+
}).authorization((allow) => allow.publicApiKey());
156156
```
157157

158158
<InlineFilter filters={["javascript", "angular", "react-native", "react", "nextjs", "vue", "android", "flutter"]}>
@@ -206,7 +206,7 @@ const schema = a.schema({
206206
Todo: a.model({
207207
content: a.string().required(),
208208
}),
209-
});
209+
}).authorization((allow) => allow.publicApiKey());
210210
```
211211

212212
## Mark fields as arrays
@@ -219,7 +219,7 @@ const schema = a.schema({
219219
content: a.string().required(),
220220
notes: a.string().array(),
221221
}),
222-
});
222+
}).authorization((allow) => allow.publicApiKey());
223223
```
224224

225225
## Assign default values for fields
@@ -231,7 +231,7 @@ const schema = a.schema({
231231
Todo: a.model({
232232
content: a.string().default('My new Todo'),
233233
}),
234-
});
234+
}).authorization((allow) => allow.publicApiKey());
235235
```
236236
<Callout>
237237
**Note:** The `.default(...)` modifier can't be applied to required fields.

src/pages/[platform]/build-a-backend/data/data-modeling/relationships/index.mdx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,15 @@ const schema = a.schema({
6262
teamId: a.id(),
6363
// 2. Create a belongsTo relationship with the reference field
6464
team: a.belongsTo('Team', 'teamId'),
65-
})
66-
.authorization(allow => [allow.publicApiKey()]),
65+
}),
6766

6867
Team: a.model({
6968
mantra: a.string().required(),
7069
// 3. Create a hasMany relationship with the reference field
7170
// from the `Member`s model.
7271
members: a.hasMany('Member', 'teamId'),
73-
})
74-
.authorization(allow => [allow.publicApiKey()]),
75-
});
72+
}),
73+
}).authorization((allow) => allow.publicApiKey());
7674
```
7775

7876
### Create a "Has Many" relationship between records
@@ -464,7 +462,7 @@ const schema = a.schema({
464462
// from the Cart model
465463
activeCart: a.hasOne('Cart', 'customerId')
466464
}),
467-
});
465+
}).authorization((allow) => allow.publicApiKey());
468466
```
469467

470468
### Create a "Has One" relationship between records
@@ -832,7 +830,7 @@ const schema = a.schema({
832830
// highlight-next-line
833831
posts: a.hasMany('PostTag', 'tagId'),
834832
}),
835-
}).authorization(allow => [allow.publicApiKey()]);
833+
}).authorization((allow) => allow.publicApiKey());
836834
```
837835

838836
## Model multiple relationships between two models
@@ -858,7 +856,7 @@ const schema = a.schema({
858856
authoredPosts: a.hasMany('Post', 'authorId'),
859857
// highlight-end
860858
}),
861-
}).authorization(allow => [allow.publicApiKey()]);
859+
}).authorization((allow) => allow.publicApiKey());
862860
```
863861

864862
On the client-side, you can fetch the related data with the following code:
@@ -921,7 +919,7 @@ const schema = a.schema({
921919
authoredPosts: a.hasMany('Post', ['authorName', 'authorDoB']),
922920
// highlight-next-line
923921
}).identifier(['name', 'dateOfBirth']),
924-
}).authorization(allow => [allow.publicApiKey()]);
922+
}).authorization((allow) => allow.publicApiKey());
925923
```
926924

927925
## Make relationships required or optional
@@ -951,5 +949,5 @@ const schema = a.schema({
951949
authoredPosts: a.hasMany('Post', 'authorId'),
952950
// highlight-end
953951
}),
954-
})
952+
}).authorization((allow) => allow.publicApiKey());
955953
```

0 commit comments

Comments
 (0)