Skip to content

Commit

Permalink
Update Chapter 7 with info on adding User SDL (#8015)
Browse files Browse the repository at this point in the history
Add info note to Chapter 7 "Accessing currentUser in the API side" with command to add User SDL and service for users who skipped using the tutorial repo at Intermission

Co-authored-by: David Price <thedavid@thedavidprice.com>
  • Loading branch information
2 people authored and jtoar committed Apr 11, 2023
1 parent 1252c12 commit bdf2640
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions docs/docs/tutorial/chapter7/api-side-currentuser.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,47 @@ model User {
}
```
:::info User SDL
We created a User model in Chapter 4 when we set up authentication for our blog. Redwood's `setup auth dbAuth` command generated two files for us that manage authentication: the `auth` file in `api/src/lib/`, and the `auth` file in `api/src/functions/`. Both of these files use our PrismaClient directly to work with the User model, so we didn't need to set up an SDL or services for the User model.
If you followed our recommendation in the Intermission to use the Example repo, the User SDL and service is already added for you. If not, you'll need to add it yourself:
```bash
yarn rw g sdl User --no-crud
```
We'll comment out the sensitive fields of our GraphQL User type so there's no chance of them leaking:
<Tabs groupId="js-ts">
<TabItem value="js" label="JavaScript">
```jsx title="api/src/graphql/users.sdl.js"
type User {
...
# hashedPassword: String!
# salt: String!
# resetToken: String
# resetTokenExpiresAt: DateTime
}
```
</TabItem>
<TabItem value="ts" label="TypeScript">
```tsx title="api/src/graphql/users.sdl.tsx"
type User {
...
# hashedPassword: String!
# salt: String!
# resetToken: String
# resetTokenExpiresAt: DateTime
}
```
</TabItem>
</Tabs>
:::
### Migrate the Database
Next, migrate the database to apply the changes (when given the option, name the migration something like "add userId to post"):
Expand Down

0 comments on commit bdf2640

Please sign in to comment.