Access denied in docker using graphQL

Hello, I followed the dev guide to have faunaDB running on docker, tried with several commands but even when I get the message of FaunaDB is ready I access it via js. sdk, but when I try to get something from the graphQL endpoint I got either “Invalid database secret.” or “Invalid authorization header.” even though I’m using the same secret as in the sdk (the default “secret” value, or it’s equivalent in base64 (already tried that))
so, could somebody give me some insight with that local environment graphQL setup?
as a side note I tried joining the slack, but ain’t working

@whitte I think you’re having the same issue that I was having when I first tried to use the Docker image. The hardcoded secret “secret” that you start out with is like the master password for the DB software. You have to use it to create a database first, and then create a key for that database, and then you can use that database key’s secret to setup graphql and manipulate the database.

Here i create a new database and get its key

client = new faunadb.Client({
  secret: 'secret'
})

const createDatabase = devDbName => q.Let(
      {
        devDbDoc: q.CreateDatabase({
          name: devDbName
        })
      },
      q.CreateKey({
        role: 'admin',
        database: q.Select('ref', q.Var('devDbDoc'))
      })
    )
  
const { secret } = await client.query(createDatabase('someDbName'))

Now the string stored in the variable secret is an admin key for your newly created database.

Hey thanks for the reply, I was about to reply cause I tried and I didn’t work, but I recalled something I saw in the forum, mixed it with the code you put and worked fine.
Seems kinda verbose to get to this point but ok, thanks a lot, I was about to return to mySQL :joy:

for now gonna put here what worked for me, probably will create something later to boilerplate this idk.

const { Client, query: q } = require("faunadb");
const client = new Client({
  secret: "secret",
  domain: "localhost",
  port: 8443,
  scheme: "http",
});

const createDatabase = (devDbName) =>
  q.Let(
    {
      devDbDoc: q.CreateDatabase({
        name: devDbName,
      }),
    },
    q.CreateKey({
      role: "admin",
      database: q.Select("ref", q.Var("devDbDoc")),
    })
  );

(async () => {
  console.log("Start!");
  try {
    const { secret: secretKey } = await client.query(createDatabase("someDbName"));
    console.log(`there is your secret key: ${secretKey}`);
  } catch (error) {
    console.error(error);
  }
})();

Hi @whitte ,

as a side note I tried joining the slack, but ain’t working

I have DMed you an invite link to join the Fauna community slack. Please give that a try!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.