<commit_before>---
title: Applying Authentication
pageTitle: "Server-side Authentication with GraphQL, Javascript & Node.js Tutorial"
description: "Learn best practices for implementing email-password authentication on a GraphQL Server with Javascript, Node.js & Express."
question: What is the "connect" argument in a Prisma mutation used for?
answers: ["It connects your application schema with the Prisma schema", "It creates a TCP connection", "It's used to connect two nodes in the database via a relation", "There is connect argument in Prisma mutations"]
correctAnswer: 3
---

In the last section, you implemented a `signup` and `login` mutation which both return authentication token for your users. In this section, you'll learn how you can _use_ authentication tokens to associate an incoming request with a user of your application.

### Creating a relation between `User` and `Link`

Looking back at the requirements from the "Getting Started"-section, we actually stated that only _authenticated_ users should be able to create new `Link` elements. However, right now, the `post` mutation is available for everyone - so you should change that to properly account for that requirement!

The first thing to do is update the data model again! You want to create a relationship between the `User` and the `Link` type which expresses that one `User` can _post_ many `Link`s.

<Instruction>

Open `database/datamodel.graphql` and adjust the `User` and `Link` types as follows:

```graphql{5,13}(path=".../hackernews-node/database/datamodel.graphql")
type Link {
  id: ID! @unique
  description: String!
  url: String!
  postedBy: User
}

type User {
  id: ID! @unique
  name: String!
  email: String! @unique
  password: String!
  links: [Link!]!
}<commit_msg>Added correct answer on 5-appling-authentication.md<commit_after>---
title: Applying Authentication
pageTitle: "Server-side Authentication with GraphQL, Javascript & Node.js Tutorial"
description: "Learn best practices for implementing email-password authentication on a GraphQL Server with Javascript, Node.js & Express."
question: What is the "connect" argument in a Prisma mutation used for?
answers: ["It connects your application schema with the Prisma schema", "It creates a TCP connection", "It's used to connect two nodes in the database via a relation", "There is connect argument in Prisma mutations"]
correctAnswer: 2
---

In the last section, you implemented a `signup` and `login` mutation which both return authentication token for your users. In this section, you'll learn how you can _use_ authentication tokens to associate an incoming request with a user of your application.

### Creating a relation between `User` and `Link`

Looking back at the requirements from the "Getting Started"-section, we actually stated that only _authenticated_ users should be able to create new `Link` elements. However, right now, the `post` mutation is available for everyone - so you should change that to properly account for that requirement!

The first thing to do is update the data model again! You want to create a relationship between the `User` and the `Link` type which expresses that one `User` can _post_ many `Link`s.

<Instruction>

Open `database/datamodel.graphql` and adjust the `User` and `Link` types as follows:

```graphql{5,13}(path=".../hackernews-node/database/datamodel.graphql")
type Link {
  id: ID! @unique
  description: String!
  url: String!
  postedBy: User
}

type User {
  id: ID! @unique
  name: String!
  email: String! @unique
  password: String!
  links: [Link!]!
}
{'fraction_non_alphanumeric': 0.0797872340425532, 'fraction_numerical': 0.0025195968645016797, 'mean_word_length': 4.857377049180328, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4039865', 'n_tokens_mistral': 984, 'n_tokens_neox': 923, 'n_words': 484}