/nextjs-sample

Next.js sample project (Google Auth)

Primary LanguageJavaScript

Sample Next.js app

About:

  • Simple Next.js app that uses the OpenAI API to generate text based on a prompt.

Development Setup:

  • Clone the repo:
git clone git@github.com:boolfalse/nextjs-sample.git && cd nextjs-sample
  1. Install dependencies (Node.js v18+)
npm install
  1. Get the Google OAuth credentials.
  • Create a new project in the Google Cloud Console
  • Set up the OAuth consent screen
  • Create an OAuth client ID
  • Add the authorized redirect URI as http://localhost:3000/api/auth/callback/google
  • Setup the .env file as described in .env.example
OAUTH_GOOGLE_CLIENT_ID="************-********************************.apps.googleusercontent.com"
OAUTH_GOOGLE_CLIENT_SECRET="******-****************************"
OAUTH_GOOGLE_REDIRECT_URI="http://localhost:3000/api/auth/callback/google"
  1. Get the MongoDB credentials:
  • Create a new project in the MongoDB Cloud
  • Create a new cluster
  • Create a new database user
  • Setup the .env file as described in .env.example
MONGODB_DATABASE="<database>"
MONGODB_URI="mongodb+srv://<username>:<password>@<cluster-url>/<database>?retryWrites=true&w=majority"
  1. Setup NextAuth credentials:
  • Run the following command:
openssl rand -base64 32
  • Setup the .env file as described in .env.example
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_URL_INTERNAL="http://localhost:3000"
NEXTAUTH_SECRET="********************************************"
  1. Run the app:
npm run dev
  1. Open the app in the browser.

Resources:

Author: