This is a Next.js project. It also requires a Postgresql database. A docker-compose.yml
file is included
for convenience so a test environment can be bootstrapped quickly. You do not have to use the
docker-compose.yml
file and probably won't use it on production but provision the Postgresql separately.
The following instructions are geared towards a local setup on a Development machine.
This setup is required for Auth-related stuff to work.
- Sign up with Auth0: https://auth0.com
- A default application is created. We'll use that. Click on Applications and then Applications then the sole app Default App
- Update the Name to whatever is appropriate
- Application Type should be
Regular Web Application
- Token Endpoint Authentication Method should be
Post
- Allowed Callback URLs should be
http://localhost:3000/api/auth/callback/auth0
. (Note that this can be found by running the app and goinge here http://localhost:3000/api/auth/providers) - Allowed Logout URLs should be set to
http://localhost:3000
. This is soreturnTo
query param will work.
You'll need to create a .env.local
file with the following:
PGUSER=docker
PGHOST=localhost
PGDATABASE=docker
PGPASSWORD=docker
PGPORT=5432
NEXT_PUBLIC_AUTH0_CLIENT_ID=...
AUTH0_CLIENT_SECRET=...
NEXT_PUBLIC_AUTH0_DOMAIN=...
Obtain the three Auth0-related values from: https://manage.auth0.com/dashboard and place in .env.local
You'll need an .env.test.local
which will be similar to .env.local
. The following values should work:
PGUSER=docker
PGHOST=localhost
PGDATABASE=docker
PGPASSWORD=docker
PGPORT=15432
Run tests with npm run test
. This will run Jest.
# 0. Ensure all dependencies are installed
npm install
# 1. Start everything
npm run local
# The above command takes over the terminal. Start a new terminal and continue.
# 2. Create symlink .env.db-setup pointing to .env.local
ln -s .env.local .env.db-setup
# 3. Create Users table
npm run db-setup
# 4. Start your Next.js app
npm run dev
Visit http://localhost:3000
- Don't forget to do a one-time import of
quiz_db.sql
into your Postgresql instance
# For example
psql -U postgres -h host.somewhere -p 5432 moonshot < quiz_db.sql
- Example Code: https://next-auth.js.org/getting-started/example
- Auth0 Provider: https://next-auth.js.org/providers/auth0
- REST API: https://next-auth.js.org/getting-started/rest-api
- User Data Storage: https://auth0.com/docs/security/data-security/user-data-storage
- Next.js Guide: https://auth0.com/docs/quickstart/webapp/nextjs