Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Chapter 7 with info on adding User SDL #8015

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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