/next-with-auth

Next.js with next-auth; supports credentials and google sign-in.

Primary LanguageJavaScript

This is a Next.js project bootstrapped with create-next-app. Authentication package is next-auth.

Netlify live demo: https://ubiquitous-souffle-96df03.netlify.app/signin

Getting Started

Clone the repo:

git clone 

Install dependencies:

npm install

Create .env.local file:
In order to use the local test user, you will need to:

  1. Create a new file, .env.local in the root directory of the project on your local machine (it will be ignored by git).
  2. Run this command in your terminal (this generates a token for your app to use locally to decode the JWT it generates):
openssl rand -base64 32
  1. Add the following values to .env.local:
NEXTAUTH_SECRET = your-generated-token-from-the-command-above
NEXTAUTH_URL = http://localhost:3000
  1. To use the Google login option locally: Sign up for Google Cloud console account
    and generate the tokens below per the directions there.
  2. Add them in .env.local as shown:
GOOGLE_CLIENT_ID = your-google-client-id
GOOGLE_CLIENT_SECRET = your-google-client-secret

Start the dev server:

npm run dev

Open http://localhost:3000/signin with your browser to see the result.

NOTE: There is currently only a single user that can be authenticated with email/password; use this user to test:

Email: jsmith@email.com  
Password: test12345

You will need a gmail account to use the Login with Google feature.

Once logged in, you will be taken to the /me page, a basic page showing your session details.
Once signed out, you will be redirected to the /signin page.

Learn More

To learn more about Next.js, take a look at the following resources: