From 45d52e6150901e137e31c673006ac1bf2111284f Mon Sep 17 00:00:00 2001 From: Jon Wire Date: Thu, 26 Sep 2024 16:02:16 -0500 Subject: [PATCH 1/2] add missing auth rules to model snippets on data modeling pages --- .../data/data-modeling/add-fields/index.mdx | 14 +++++++------- .../data/data-modeling/relationships/index.mdx | 12 +++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/data/data-modeling/add-fields/index.mdx b/src/pages/[platform]/build-a-backend/data/data-modeling/add-fields/index.mdx index 334dbcb5326..37d008a8cdf 100644 --- a/src/pages/[platform]/build-a-backend/data/data-modeling/add-fields/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/data-modeling/add-fields/index.mdx @@ -64,7 +64,7 @@ a.schema({ }), content: a.string(), }), -}); +}).authorization((allow) => allow.publicApiKey()); ``` **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({ User: a.model({ lastKnownLocation: a.ref('Location'), }), -}); +}).authorization((allow) => allow.publicApiKey()); ``` @@ -131,7 +131,7 @@ a.schema({ privacySetting: a.enum(['PRIVATE', 'FRIENDS_ONLY', 'PUBLIC']), content: a.string(), }), -}); +}).authorization((allow) => allow.publicApiKey()); ``` Long-form approach @@ -152,7 +152,7 @@ a.schema({ Video: a.model({ privacySetting: a.ref('PrivacySetting'), }), -}); +}).authorization((allow) => allow.publicApiKey()); ``` @@ -206,7 +206,7 @@ const schema = a.schema({ Todo: a.model({ content: a.string().required(), }), -}); +}).authorization((allow) => allow.publicApiKey()); ``` ## Mark fields as arrays @@ -219,7 +219,7 @@ const schema = a.schema({ content: a.string().required(), notes: a.string().array(), }), -}); +}).authorization((allow) => allow.publicApiKey()); ``` ## Assign default values for fields @@ -231,7 +231,7 @@ const schema = a.schema({ Todo: a.model({ content: a.string().default('My new Todo'), }), -}); +}).authorization((allow) => allow.publicApiKey()); ``` **Note:** The `.default(...)` modifier can't be applied to required fields. diff --git a/src/pages/[platform]/build-a-backend/data/data-modeling/relationships/index.mdx b/src/pages/[platform]/build-a-backend/data/data-modeling/relationships/index.mdx index e7d030c32fd..d1cdcf93c84 100644 --- a/src/pages/[platform]/build-a-backend/data/data-modeling/relationships/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/data-modeling/relationships/index.mdx @@ -62,17 +62,15 @@ const schema = a.schema({ teamId: a.id(), // 2. Create a belongsTo relationship with the reference field team: a.belongsTo('Team', 'teamId'), - }) - .authorization(allow => [allow.publicApiKey()]), + }), Team: a.model({ mantra: a.string().required(), // 3. Create a hasMany relationship with the reference field // from the `Member`s model. members: a.hasMany('Member', 'teamId'), - }) - .authorization(allow => [allow.publicApiKey()]), -}); + }), +}).authorization(allow => [allow.publicApiKey()]); ``` ### Create a "Has Many" relationship between records @@ -464,7 +462,7 @@ const schema = a.schema({ // from the Cart model activeCart: a.hasOne('Cart', 'customerId') }), -}); +}).authorization(allow => [allow.publicApiKey()]); ``` ### Create a "Has One" relationship between records @@ -951,5 +949,5 @@ const schema = a.schema({ authoredPosts: a.hasMany('Post', 'authorId'), // highlight-end }), -}) +}).authorization(allow => [allow.publicApiKey()]); ``` From 29ac3e3fa46ec71b3646d0713d15cf23e052d4e5 Mon Sep 17 00:00:00 2001 From: Jon Wire Date: Thu, 26 Sep 2024 16:29:24 -0500 Subject: [PATCH 2/2] un-array-atize auth rules on relationship modeling page --- .../data/data-modeling/relationships/index.mdx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/data/data-modeling/relationships/index.mdx b/src/pages/[platform]/build-a-backend/data/data-modeling/relationships/index.mdx index d1cdcf93c84..7e3934edfcf 100644 --- a/src/pages/[platform]/build-a-backend/data/data-modeling/relationships/index.mdx +++ b/src/pages/[platform]/build-a-backend/data/data-modeling/relationships/index.mdx @@ -70,7 +70,7 @@ const schema = a.schema({ // from the `Member`s model. members: a.hasMany('Member', 'teamId'), }), -}).authorization(allow => [allow.publicApiKey()]); +}).authorization((allow) => allow.publicApiKey()); ``` ### Create a "Has Many" relationship between records @@ -462,7 +462,7 @@ const schema = a.schema({ // from the Cart model activeCart: a.hasOne('Cart', 'customerId') }), -}).authorization(allow => [allow.publicApiKey()]); +}).authorization((allow) => allow.publicApiKey()); ``` ### Create a "Has One" relationship between records @@ -830,7 +830,7 @@ const schema = a.schema({ // highlight-next-line posts: a.hasMany('PostTag', 'tagId'), }), -}).authorization(allow => [allow.publicApiKey()]); +}).authorization((allow) => allow.publicApiKey()); ``` ## Model multiple relationships between two models @@ -856,7 +856,7 @@ const schema = a.schema({ authoredPosts: a.hasMany('Post', 'authorId'), // highlight-end }), -}).authorization(allow => [allow.publicApiKey()]); +}).authorization((allow) => allow.publicApiKey()); ``` On the client-side, you can fetch the related data with the following code: @@ -919,7 +919,7 @@ const schema = a.schema({ authoredPosts: a.hasMany('Post', ['authorName', 'authorDoB']), // highlight-next-line }).identifier(['name', 'dateOfBirth']), -}).authorization(allow => [allow.publicApiKey()]); +}).authorization((allow) => allow.publicApiKey()); ``` ## Make relationships required or optional @@ -949,5 +949,5 @@ const schema = a.schema({ authoredPosts: a.hasMany('Post', 'authorId'), // highlight-end }), -}).authorization(allow => [allow.publicApiKey()]); +}).authorization((allow) => allow.publicApiKey()); ```