Unverified Commit 28c13bd5 authored by Lee Robinson's avatar Lee Robinson Committed by GitHub

Rename environment variable in Fauna example. (#27712)

To make it more clear you're using the admin key on the server.
parent aa929c4b
...@@ -26,22 +26,15 @@ You can start with this template [using `create-next-app`](#using-create-next-ap ...@@ -26,22 +26,15 @@ You can start with this template [using `create-next-app`](#using-create-next-ap
To use a live Fauna database, create a database at [dashboard.fauna.com](https://dashboard.fauna.com/) and generate an admin token by going to the **Security** tab on the left and then click **New Key**. Give the new key a name and select the 'Admin' Role. Copy the token since the setup script will ask for it. Do not use it in the frontend, it has superpowers which you don't want to give to your users. To use a live Fauna database, create a database at [dashboard.fauna.com](https://dashboard.fauna.com/) and generate an admin token by going to the **Security** tab on the left and then click **New Key**. Give the new key a name and select the 'Admin' Role. Copy the token since the setup script will ask for it. Do not use it in the frontend, it has superpowers which you don't want to give to your users.
The database can then be set up with the delivered setup by running: ### Setting Up Your Schema
``` The Next.js and Fauna example includes a setup script (`npm run setup`). After providing your admin token, the script will:
npm run setup
# or using yarn
yarn setup
```
This script will ask for the admin token. Once you provide it with a valid token, this is what the script automatically does for you:
- **Import the GraphQL schema**, by importing a GraphQL schema in Fauna, Fauna automatically sets up collections and indexes to support your queries. This is now done for you with this script but can also be done from the [dashboard.fauna.com](https://dashboard.fauna.com/) UI by going to the GraphQL tab - **Import your GraphQL schema:** Fauna automatically sets up collections and indexes to support your queries. You can view these in your [project dashboard](https://dashboard.fauna.com/) under **GraphQL**.
- **Create an index and UDF**, in order to implement custom sorting (by createdAt field), we need to create a GraphQL resolver that uses [UDF](https://docs.fauna.com/fauna/current/api/graphql/functions?lang=javascript) based on sorting index. - **Create an index and function:** The script will create a GraphQL resolver that uses [User-defined functions](https://docs.fauna.com/fauna/current/api/graphql/functions?lang=javascript) based on a sorting index.
- **Create a role suitable for the Client**, Fauna has a security system that allows you to define which resources can be accessed for a specific token. That's how we limit our clients powers, feel free to look at the scripts/setup.js script to see how we make roles and tokens. - **Create a scoped token:** This token is for use on the client side. The admin key can be used on the server side.
- **Create a token for that role**, this is the token to be used in the app.
At the end, a `.env.local` [file](https://nextjs.org/docs/basic-features/environment-variables) will be created for you with the newly generated client token assigned to an environment variable. After the script completes, a `.env.local` [file](https://nextjs.org/docs/basic-features/environment-variables) will be created for you with the newly generated client token assigned to an Environment Variable.
### Run locally ### Run locally
...@@ -49,14 +42,7 @@ Install packages, set up if needed, then run the development server: ...@@ -49,14 +42,7 @@ Install packages, set up if needed, then run the development server:
```bash ```bash
npm install npm install
# if you haven't run setup yet
npm run setup
npm run dev npm run dev
# or using yarn
yarn
# if you haven't run setup yet
yarn setup
yarn dev
``` ```
Your app should be up and running on [http://localhost:3000](http://localhost:3000)! Your app should be up and running on [http://localhost:3000](http://localhost:3000)!
import { GraphQLClient, gql } from 'graphql-request' import { GraphQLClient, gql } from 'graphql-request'
const FAUNADB_GRAPHQL_ENDPOINT = 'https://graphql.fauna.com/graphql' const graphQLClient = new GraphQLClient('https://graphql.fauna.com/graphql', {
const FAUNADB_SECRET = process.env.FAUNADB_SECRET
const graphQLClient = new GraphQLClient(FAUNADB_GRAPHQL_ENDPOINT, {
headers: { headers: {
authorization: `Bearer ${FAUNADB_SECRET}`, authorization: `Bearer ${process.env.FAUNA_ADMIN_KEY}`,
}, },
}) })
......
...@@ -153,7 +153,7 @@ const main = async () => { ...@@ -153,7 +153,7 @@ const main = async () => {
console.log('2. Created Fauna resources') console.log('2. Created Fauna resources')
await fs.promises.writeFile('.env.local', `FAUNADB_SECRET=${secret}\n`) await fs.promises.writeFile('.env.local', `FAUNADB_CLIENT_SECRET=${secret}\n`)
console.log('3. Created .env.local file with secret') console.log('3. Created .env.local file with secret')
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment