Error: unauthorized 401

hi folks, how are you? I’m new to Fauna and it’s giving an error when I create a new user in my collection called ‘tutors’.

first i created a file to declare the Client, with the FAUNADB_KEY on my .env.local

//fauna.ts

import { Client } from 'faunadb';

export const fauna = new Client({
  secret: process.env.FAUNADB_KEY,
  domain: 'db.fauna.com'
})

and then i tried to create my first document:

const handleCreateUser: SubmitHandler<CreateTutorFormData> = async data => {
    await fauna.query(
      q.Create(
        q.Collection('tutors'),
        {
          data: {
            name: data.name,
            email: data.email,
            cpf: data.cpf,
            phone: data.phone,
            address: data.address,
          }
        }
      )
    )
      .then(res => res)
      .catch(err => console.error('Error: ', err.message));

  };

on the console, shows me:

Captura de Tela 2021-10-05 às 20.06.40

obs: the stack that i’m using is: TypeScript, ReactJS, NextJS.

anyone can help me?

Welcome @eduardomarr!

One thing to check is that you’re using the correct endpoint for your database. db.fauna.com is used for the Classic region group. If you’re using either the US or EU ones you would want to change that to either db.us.fauna.com or db.eu.fauna.com, respectively.

Cory

Hi @eduardomarr,

Are you still having difficulty or did you get your auth working?