This Next.js template demonstrates how to use Redis as a session store for app auth using multiple providers like GitHub and Discord.
This Next.js project demonstrates how to use Redis as a session store for authentication. The application supports multiple authentication providers, offering a scalable and performant solution for your web applications.
Follow these steps to deploy your application with Redis Cloud on Vercel:
REDIS_URL
environment variable.Install dependencies:
npm install
# or
yarn install
# or
pnpm install
Run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
Open http://localhost:3000 in your browser to see the application.
Ensure you have a Redis server running and configure the connection in your .env
file:
REDIS_URL=redis://localhost:6379
Note: If you deployed using Vercel with Redis Cloud, this will be automatically set for you.
Configure authentication providers by setting or omitting their respective environment variables in your .env
file:
NEXTAUTH_SECRET=your_nextauth_secret
# GitHub Authentication
GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
# Discord Authentication
DISCORD_CLIENT_ID=your_discord_client_id
DISCORD_CLIENT_SECRET=your_discord_client_secret
CLIENT_ID
and CLIENT_SECRET
CLIENT_ID
and CLIENT_SECRET
GITHUB_CLIENT_ID
and GITHUB_CLIENT_SECRET
Example:
GITHUB_CLIENT_ID=1234567890abcdef1234
GITHUB_CLIENT_SECRET=1234567890abcdef1234567890abcdef12345678
Discord
DISCORD_CLIENT_ID
and DISCORD_CLIENT_SECRET
Example:
DISCORD_CLIENT_ID=123456789012345678
DISCORD_CLIENT_SECRET=abcdefghijklmnopqrstuvwxyz123456
To add more authentication providers:
app/api/auth/[...nextauth]/route.js
Example for adding Google provider:
import GoogleProvider from "next-auth/providers/google";
// In the providers array:
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
For more information on adding and configuring providers, refer to the NextAuth.js documentation on providers.
Generate a secure NEXTAUTH_SECRET
:
openssl rand -base64 32
Add this to your Vercel project's environment variables as NEXTAUTH_SECRET
.
This application leverages Redis for efficient session data storage, offering:
/
├── app/ # Next.js pages and API routes
├── components/ # Reusable React components
├── lib/ # Utility functions and custom adapters
├── hooks/ # Custom React hooks
└── styles/ # Global and brand-specific styles
npm run dev
: Run the app in development modenpm run build
: Build the app for productionnpm run start
: Start the production buildnpm run lint
: Run linting on the codebaseExplore these resources to deepen your understanding:
We welcome contributions! If you have ideas, suggestions, or encounter issues, please open an issue or submit a pull request.
This project is open source and available under the MIT License.
This Next.js template demonstrates how to use Redis as a session store for app auth using multiple providers like GitHub and Discord.
This Next.js project demonstrates how to use Redis as a session store for authentication. The application supports multiple authentication providers, offering a scalable and performant solution for your web applications.
Follow these steps to deploy your application with Redis Cloud on Vercel:
REDIS_URL
environment variable.Install dependencies:
npm install
# or
yarn install
# or
pnpm install
Run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
Open http://localhost:3000 in your browser to see the application.
Ensure you have a Redis server running and configure the connection in your .env
file:
REDIS_URL=redis://localhost:6379
Note: If you deployed using Vercel with Redis Cloud, this will be automatically set for you.
Configure authentication providers by setting or omitting their respective environment variables in your .env
file:
NEXTAUTH_SECRET=your_nextauth_secret
# GitHub Authentication
GITHUB_CLIENT_ID=your_github_client_id
GITHUB_CLIENT_SECRET=your_github_client_secret
# Discord Authentication
DISCORD_CLIENT_ID=your_discord_client_id
DISCORD_CLIENT_SECRET=your_discord_client_secret
CLIENT_ID
and CLIENT_SECRET
CLIENT_ID
and CLIENT_SECRET
GITHUB_CLIENT_ID
and GITHUB_CLIENT_SECRET
Example:
GITHUB_CLIENT_ID=1234567890abcdef1234
GITHUB_CLIENT_SECRET=1234567890abcdef1234567890abcdef12345678
Discord
DISCORD_CLIENT_ID
and DISCORD_CLIENT_SECRET
Example:
DISCORD_CLIENT_ID=123456789012345678
DISCORD_CLIENT_SECRET=abcdefghijklmnopqrstuvwxyz123456
To add more authentication providers:
app/api/auth/[...nextauth]/route.js
Example for adding Google provider:
import GoogleProvider from "next-auth/providers/google";
// In the providers array:
GoogleProvider({
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
}),
For more information on adding and configuring providers, refer to the NextAuth.js documentation on providers.
Generate a secure NEXTAUTH_SECRET
:
openssl rand -base64 32
Add this to your Vercel project's environment variables as NEXTAUTH_SECRET
.
This application leverages Redis for efficient session data storage, offering:
/
├── app/ # Next.js pages and API routes
├── components/ # Reusable React components
├── lib/ # Utility functions and custom adapters
├── hooks/ # Custom React hooks
└── styles/ # Global and brand-specific styles
npm run dev
: Run the app in development modenpm run build
: Build the app for productionnpm run start
: Start the production buildnpm run lint
: Run linting on the codebaseExplore these resources to deepen your understanding:
We welcome contributions! If you have ideas, suggestions, or encounter issues, please open an issue or submit a pull request.
This project is open source and available under the MIT License.