1

Create Nhost Project

Create your project through the Nhost Dashboard.

2

Setup Database

Navigate to the SQL Editor of the database and run the following SQL to create a new table todos.

Make sure the option Track this is enabled
SQL Editor
CREATE TABLE todos (
  id uuid NOT NULL DEFAULT gen_random_uuid(),
  created_at timestamptz NOT NULL DEFAULT now(),
  updated_at timestamptz NOT NULL DEFAULT now(),
  user_id uuid NOT NULL,
  contents text NOT NULL,
  PRIMARY KEY (id),
  FOREIGN KEY (user_id) REFERENCES auth.users(id) ON UPDATE cascade ON DELETE cascade
);

Create Todos Table

3

Configure the todos table permissions

To set permissions for the new todos table, select the table, click on the ... to open the actions dialog, then click on Edit Permissions. Set the following permissions for the user role:

  1. Insert
    • Set Row insert permissions to Without any checks
    • Select all columns except user_id on Column insert permissions
    • Add a new Column preset and set Column Name to user_id and Column Value to X-Hasura-User-Id
    • Save

Insert Permissions

  1. Select
    • Set Row select permissions to With custom check and fill in the following rule:
      • Set Where to todos.user_id
      • Set the operator to _eq
      • Set the value to X-Hasura-User-Id
    • Select all columns except user_id on Column select permissions
    • Save

Select Permissions

  1. Update
    • Set Row update permissions to With custom check and fill in the following rule:
      • Set Where to todos.user_id
      • Set the operator to _eq
      • Set the value to X-Hasura-User-Id
    • Select all columns except user_id on Column select permissions
    • Save

Update permissions

  1. Delete
    • Set Row delete permissions to With custom check and fill in the following rule:
      • Set Where to todos.user_id
      • Set the operator to _eq
      • Set the value to X-Hasura-User-Id
    • Save

Delete permissions

4

Configure permissions to enable user file uploads

To enable file uploads by users, set the permissions as follows:

  1. Edit the files table permissions

    1. Navigate to the files table within the Database tab
    2. Click on the three dots (…) next to the files table
    3. Click on Edit Permissions
  2. Modify the Insert permission for the user role:

    1. Set Row insert permissions to Without any checks
    2. Select all columns on Column insert permissions
    3. Save

Insert Permissions

  1. Select
    • Set Row select permissions to With custom check and fill in the following rule:
      • Set Where to files.uploaded_by_user_id
      • Set the operator to _eq
      • Set the value to X-Hasura-User-Id
    • Select all columns on Column select permissions
    • Save

Select permissions

5

Bootstrap your React app

Intialize a new React project using the template @nhost/react-apollo

Terminal
npx create-react-app myapp --template @nhost/react-apollo
6

Connect your React app to the Nhost project

Copy your project’s <subdomain> and <region> values available on the dashboard overview

src/index.tsx
const nhost = new NhostClient({
  subdomain: "<subdomain>", // replace the subdomain value e.g. "hjcuuqweqwezolpolrep"
  region: "<region>", // replace the region value e.g. "eu-central-1"
});
7

Create the Todos Page and Add It to the Sidebar Navigation

8

Run the project

Run your project with npm start and enter http://localhost:3000 in your browser.