Execute create-next-app
with Yarn or npx to bootstrap the example:
npx create-next-app --example with-passport-session-auth with-passport-app
# or
yarn create next-app --example with-passport-session-auth with-passport-app
Download the example:
curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-passport-session-auth
cd with-passport-session-auth
Set required environment variables. Use .env.template
if you use a dotenv tool.
export GITHUB_CLIENTID=<your github app's client id>
export GITHUB_CLIENTSECRET=<your github app's client secret>
Install it and run:
npm install
npm run dev
# or
yarn
yarn dev
Deploy it to the cloud with now (download)
now
This example demonstrates using passport in NextJS API routes for OAuth connection flows.
Takes example of the fact that Next's micro-based API routes are compatible with connect-style middleware, with a little work.
Most of the meat of the example is in how we configure passport to work as NextJS middleware.
- add CRSF mitigation
- add JWT session token