{"id":21672381,"url":"https://github.com/redis-developer/session-store-nextjs","last_synced_at":"2025-04-12T03:52:44.127Z","repository":{"id":259237283,"uuid":"860133115","full_name":"redis-developer/session-store-nextjs","owner":"redis-developer","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-23T15:25:23.000Z","size":240,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-12T03:52:39.613Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://nextjs-redis-session-store.vercel.app","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/redis-developer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-19T22:07:13.000Z","updated_at":"2025-04-01T16:21:57.000Z","dependencies_parsed_at":"2024-10-23T19:33:02.201Z","dependency_job_id":"ec192845-0576-4e6b-8481-6e28d599e1a6","html_url":"https://github.com/redis-developer/session-store-nextjs","commit_stats":null,"previous_names":["redis-developer/session-store-nextjs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fsession-store-nextjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fsession-store-nextjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fsession-store-nextjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/redis-developer%2Fsession-store-nextjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/redis-developer","download_url":"https://codeload.github.com/redis-developer/session-store-nextjs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248514209,"owners_count":21116899,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-25T13:29:11.272Z","updated_at":"2025-04-12T03:52:44.107Z","avatar_url":"https://github.com/redis-developer.png","language":"JavaScript","readme":"# 🚀 Next.js Redis Session Store Example\n\n![Redis](https://img.shields.io/badge/Redis-DC382D?style=for-the-badge\u0026logo=redis\u0026logoColor=white)\n![Next.js](https://img.shields.io/badge/Next.js-000000?style=for-the-badge\u0026logo=next.js\u0026logoColor=white)\n![NextAuth.js](https://img.shields.io/badge/NextAuth.js-000000?style=for-the-badge\u0026logo=next.js\u0026logoColor=white)\n\nThis [Next.js](https://nextjs.org/) 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.\n\n## 📋 Table of Contents\n\n- [🚀 Deploy with Redis Cloud on Vercel](#-deploy-with-redis-cloud-on-vercel)\n- [✨ Features](#-features)\n- [🌱 Getting Started](#-getting-started)\n- [🛠️ Configuration](#️-configuration)\n- [💾 Session Management with Redis](#-session-management-with-redis)\n- [🗂️ Project Structure](#️-project-structure)\n- [📜 Available Scripts](#-available-scripts)\n- [📚 Learn More](#-learn-more)\n- [🤝 Contributing](#-contributing)\n- [📄 License](#-license)\n\n## 🚀 Deploy with Redis Cloud on Vercel\n\nFollow these steps to deploy your application with Redis Cloud on Vercel:\n\n1. Click the \"Deploy\" button below to start the deployment process:\n\n\u003ca href=\"https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fredis-developer%2Fsession-store-nextjs\u0026project-name=redis-session-store-nextjs\u0026stores=%5B%7B%22type%22%3A%22integration%22%2C%22integrationSlug%22%3A%22redis%22%2C%22productSlug%22%3A%22redis%22%7D%5D\"\u003e\n   \u003cimg src=\"https://vercel.com/button\" alt=\"Deploy with Vercel\" /\u003e\n\u003c/a\u003e\n\n2. In the Vercel UI, create a new repository for your project.\n\n![Create a new repository](./images/vercel-step-1.png?raw=true)\n\n3. Add Redis as a store in the Vercel UI. This will automatically set your `REDIS_URL` environment variable.\n\n![Add Redis Cloud store](./images/vercel-step-2.png?raw=true)\n\n4. Wait for the deployment to complete.\n\n![Add Redis Cloud store](./images/vercel-step-3.png?raw=true)\n\n5. Once deployed, use the URL of your deployed app to set up the authentication providers. See the [Configuration](#️-configuration) section below for detailed instructions for setting these up. By default, the template is configured to use GitHub and Discord. Only one provider is required.\n\n## ✨ Features\n\n- 🗄️ **Redis Session Store**: Utilizes Redis for storing session data\n- 🔐 **NextAuth.js Integration**: Implements authentication using NextAuth.js with a custom Redis adapter\n- 🌐 **Multiple Authentication Providers**: Supports GitHub and Discord authentication\n- ⚙️ **Dynamic Configuration**: Easily enable or disable authentication providers via environment variables\n\n## 🌱 Getting Started\n\n1. **Install dependencies:**\n\n   ```bash\n   npm install\n   # or\n   yarn install\n   # or\n   pnpm install\n   ```\n\n2. **Run the development server:**\n\n   ```bash\n   npm run dev\n   # or\n   yarn dev\n   # or\n   pnpm dev\n   ```\n\n3. Open [http://localhost:3000](http://localhost:3000) in your browser to see the application.\n\n## 🛠️ Configuration\n\n### Setting Up Redis\n\nEnsure you have a Redis server running and configure the connection in your `.env` file:\n\n```env\nREDIS_URL=redis://localhost:6379\n```\n\nNote: If you deployed using Vercel with Redis Cloud, this will be automatically set for you.\n\n### Enabling/Disabling Authentication Providers\n\nConfigure authentication providers by setting or omitting their respective environment variables in your `.env` file:\n\n```env\nNEXTAUTH_SECRET=your_nextauth_secret\n\n# GitHub Authentication\nGITHUB_CLIENT_ID=your_github_client_id\nGITHUB_CLIENT_SECRET=your_github_client_secret\n\n# Discord Authentication\nDISCORD_CLIENT_ID=your_discord_client_id\nDISCORD_CLIENT_SECRET=your_discord_client_secret\n```\n\n- To enable a provider: Set both the `CLIENT_ID` and `CLIENT_SECRET`\n- To disable a provider: Remove or comment out the `CLIENT_ID` and `CLIENT_SECRET`\n\n### Provider-Specific Configuration\n\n#### GitHub\n\n1. Go to [GitHub Developer Settings](https://github.com/settings/developers)\n2. Click on \"New OAuth App\"\n3. Fill in the application details:\n   - Application name: Your app name\n   - Homepage URL: https://your-vercel-app-url.vercel.app \n   - Authorization callback URL: https://your-vercel-app-url.vercel.app/api/auth/callback/github (or your local URL if you're running it locally)\n4. Click \"Register application\"\n5. Copy the Client ID and generate a new Client Secret\n6. Add these to your Vercel project's environment variables as `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET`\n\nExample:\n```\nGITHUB_CLIENT_ID=1234567890abcdef1234\nGITHUB_CLIENT_SECRET=1234567890abcdef1234567890abcdef12345678\n```\n\n#### Discord\n\n1. Go to the [Discord Developer Portal](https://discord.com/developers/applications)\n2. Click on \"New Application\"\n3. Give your application a name and create it\n4. Go to the \"OAuth2\" tab in the left sidebar\n5. Add a redirect URL: https://your-vercel-app-url.vercel.app/api/auth/callback/discord (or your local URL if you're running it locally)\n6. Copy the Client ID and Client Secret\n7. Add these to your Vercel project's environment variables as `DISCORD_CLIENT_ID` and `DISCORD_CLIENT_SECRET`\n\nExample:\n```\nDISCORD_CLIENT_ID=123456789012345678\nDISCORD_CLIENT_SECRET=abcdefghijklmnopqrstuvwxyz123456\n```\n\n### Adding Additional Providers\n\nTo add more authentication providers:\n\n1. Install the provider package (if required)\n2. Update the NextAuth configuration in `app/api/auth/[...nextauth]/route.js`\n3. Add the necessary environment variables\n\nExample for adding Google provider:\n\n```javascript\nimport GoogleProvider from \"next-auth/providers/google\";\n\n// In the providers array:\nGoogleProvider({\n  clientId: process.env.GOOGLE_CLIENT_ID,\n  clientSecret: process.env.GOOGLE_CLIENT_SECRET,\n}),\n```\n\nFor more information on adding and configuring providers, refer to the [NextAuth.js documentation on providers](https://next-auth.js.org/providers/).\n\n### NextAuth.js Secret\n\nGenerate a secure `NEXTAUTH_SECRET`:\n\n```bash\nopenssl rand -base64 32\n```\n\nAdd this to your Vercel project's environment variables as `NEXTAUTH_SECRET`.\n\n## 💾 Session Management with Redis\n\nThis application leverages Redis for efficient session data storage, offering:\n\n- ⚡ **High Performance**: Fast read/write operations with in-memory data store\n- 📈 **Scalability**: Share session data across multiple application instances\n- 💽 **Optional Persistence**: Configure Redis to persist data to disk for recovery\n\n## 🗂️ Project Structure\n\n```\n/\n├── app/            # Next.js pages and API routes\n├── components/     # Reusable React components\n├── lib/            # Utility functions and custom adapters\n├── hooks/          # Custom React hooks\n└── styles/         # Global and brand-specific styles\n```\n\n## 📜 Available Scripts\n\n- `npm run dev`: Run the app in development mode\n- `npm run build`: Build the app for production\n- `npm run start`: Start the production build\n- `npm run lint`: Run linting on the codebase\n\n## 📚 Learn More\n\nExplore these resources to deepen your understanding:\n\n- [Next.js Documentation](https://nextjs.org/docs)\n- [NextAuth.js Documentation](https://next-auth.js.org/getting-started/introduction)\n- [Redis Documentation](https://redis.io/docs/)\n- [Redis Clients for Node.js](https://redis.io/docs/clients/nodejs/)\n- [Environment Variables in Next.js](https://nextjs.org/docs/basic-features/environment-variables)\n\n## 🤝 Contributing\n\nWe welcome contributions! If you have ideas, suggestions, or encounter issues, please open an issue or submit a pull request.\n\n## 📄 License\n\nThis project is open source and available under the [MIT License](LICENSE).","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis-developer%2Fsession-store-nextjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fredis-developer%2Fsession-store-nextjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fredis-developer%2Fsession-store-nextjs/lists"}