# Authentication with FT4 accounts · A simple Chromia app with Rell and React · Learn Chromia

> This lesson shows how to authenticate users with FT4 accounts.

Source: https://chromia.com/learn/my-news-feed/module-one/create-accounts/authentication/

A simple Chromia app with Rell and ReactLesson 9 of 27

1. [01Building a simple Chromia app with Rell, React and FT4](https://chromia.com/learn/my-news-feed/introduction/)
2. [02Project setup complete](https://chromia.com/learn/my-news-feed/setup/)

Module 1: A Rell backend with FT accounts

1. [03Overview](https://chromia.com/learn/my-news-feed/module-one/)
2. [04Part 1: Designing the database schema](https://chromia.com/learn/my-news-feed/module-one/data-modeling/)
3. [05The data model](https://chromia.com/learn/my-news-feed/module-one/data-modeling/tables/)
4. [06Code the model in Rell](https://chromia.com/learn/my-news-feed/module-one/data-modeling/model/)
5. [07Part 2: Set up accounts](https://chromia.com/learn/my-news-feed/module-one/create-accounts/)
6. [08FT4 accounts configuration](https://chromia.com/learn/my-news-feed/module-one/create-accounts/install-configure-ft4/)
7. [09Authentication with FT4 accounts](https://chromia.com/learn/my-news-feed/module-one/create-accounts/authentication/)
8. [10Part 3: A closer look at operations and queries](https://chromia.com/learn/my-news-feed/module-one/operations-queries/)
9. [11Basic operations](https://chromia.com/learn/my-news-feed/module-one/operations-queries/basic-operations/)
10. [12Basic queries](https://chromia.com/learn/my-news-feed/module-one/operations-queries/write-queries/)
11. [13Part 4: Validating and verifying input](https://chromia.com/learn/my-news-feed/module-one/input-verification/)
12. [14Verify inputs](https://chromia.com/learn/my-news-feed/module-one/input-verification/input-verification/)
13. [15Run unit tests](https://chromia.com/learn/my-news-feed/module-one/input-verification/tests/)
14. [16Part 5: How the dapp project is organized](https://chromia.com/learn/my-news-feed/module-one/project-structure/)
15. [17Work with Rell modules](https://chromia.com/learn/my-news-feed/module-one/project-structure/modules/)
16. [18Add modules to your dapp](https://chromia.com/learn/my-news-feed/module-one/project-structure/incorporate-modules/)
17. [19Part 6: Sign up users with an EVM wallet](https://chromia.com/learn/my-news-feed/module-one/register-evm-accounts/)
18. [20Sign up accounts with EVM wallets](https://chromia.com/learn/my-news-feed/module-one/register-evm-accounts/register-evm-accounts/)
19. [21Test the registration](https://chromia.com/learn/my-news-feed/module-one/register-evm-accounts/test-registration/)

Module 2: The React project

1. [22Overview](https://chromia.com/learn/my-news-feed/module-two/)
2. [23Set up the project](https://chromia.com/learn/my-news-feed/module-two/setup/)
3. [24Project scaffold](https://chromia.com/learn/my-news-feed/module-two/scaffold/)
4. [25Connect the client](https://chromia.com/learn/my-news-feed/module-two/connecting-the-client/)
5. [26Summary and manual testing](https://chromia.com/learn/my-news-feed/module-two/summary-and-tests/)

1. [27What is next?](https://chromia.com/learn/my-news-feed/what-next/)

[Learn](https://chromia.com/learn/)[A simple Chromia app with Rell and React](https://chromia.com/learn/my-news-feed/)

09 / 27Module 1: A Rell backend with FT accountsBeginner

# Authentication with FT4 accounts

This lesson shows how to authenticate users with FT4 accounts.

FT4 makes authentication straightforward. Start by importing the `auth` module:

src/news\_feed/module.rell

```nolines
import lib.ft4.auth;
```

Then call `auth.authenticate` inside your operations:

src/news\_feed/operations.rell

```
operation make_post(content: text) {
  val account = auth.authenticate();
  require(content.size() <= 255, "A post cannot be longer than 255 characters");
  val user = user @ { account };
  create post ( user, content );
}

operation follow_user(follow_id: byte_array) {
  val account = auth.authenticate();
  val user = user @ { account };
  val follow = require_user(follow_id);
  create follower ( user = follow, follower = user );
}

operation unfollow_user(unfollow_id: byte_array) {
  val account = auth.authenticate();
  val user = user @ { account };
  val follow = require_user(unfollow_id);
  delete follower @? { .user == follow, .follower == user };
}
```

Calling `auth.authenticate` takes care of authentication for you, which simplifies your code and improves security. Your operations also no longer need to receive the user's public key as a parameter.

Authentication only takes effect once you register an [auth handler](https://docs.chromia.com/build/ft4/backend/authentication/auth/#the-authenticate-function). Add this code to your Rell module:

src/news\_feed/auth.rell

```
@extend(auth.auth_handler)
function () = auth.add_auth_handler(
  flags = ["S"]
);
```

This extension function registers a handler with the "S" flag, the same flag you used when creating the account. The handler is global, so it applies to every operation in your app that calls `auth.authenticate`. To attach a handler to one specific operation or module instead, pass a scope argument to `auth.add_auth_handler`.

Written for this site from Chromia’s public course. Code samples are the course’s own.

[← Previous**FT4 accounts configuration**](https://chromia.com/learn/my-news-feed/module-one/create-accounts/install-configure-ft4/)[Next →**Part 3: A closer look at operations and queries**](https://chromia.com/learn/my-news-feed/module-one/operations-queries/)
