/next-auth-poc

A Proof of Concept using Next Auth

Primary LanguageTypeScriptISC LicenseISC

NextAuth/Keycloak Accelerator

next-auth on npm TypeScript

Overview

This is an example application that shows how next-auth is applied to a basic Next.js app with Keycloak.

Go to next-auth.js.org for more information and documentation on NextAuth.

Clone the repository and install dependencies

git clone https://github.com/jonryser/next-auth-poc.git
cd next-auth-poc
yarn

Keycloak

Keycloak

Configure KeyCloak

Use the Keycloak Accelerator to get the Keycloak server setup.

Install the startup realm that is included with the Keycloak accelerator.

Once the Keycloak server is running and the startup ("NextAuth POC") realm is installed - switch to the "NextAuth POC" realm - go to Realm settings -> Email - update the Connection & Authentication values to working email settings

Configure the local environment

Copy the .env.local.example file in this directory to .env.local (which will be ignored by Git):

cp .env.local.example .env.local

Update the Keycloak env vars:

KEYCLOAK_AUTHORIZATION=http://localhost:8180/realms/NextAuth_POC/protocol/openid-connect/auth
KEYCLOAK_CLIENT_ID=next-auth-poc
# The client secret can be any value
KEYCLOAK_CLIENT_SECRET=5ghC0E06conPaarRPQGId7VonTWIsq0u
KEYCLOAK_ISSUER=http://localhost:8180/realms/NextAuth_POC
KEYCLOAK_WELLKNOWN=http://localhost:8180/realms/NextAuth_POC/.well-known/openid-configuration

Start the application

To run your site locally, use:

yarn dev

To run it in production mode, use:

yarn build
yarn start

Preparing for Production

Follow the Deployment documentation or deploy the example instantly using Vercel

Deploy with Vercel

Acknowledgements

Built off the original next-auth-example repo at https://github.com/nextauthjs/next-auth-example.git