π Web OAuth β‘οΈ Using with Next.js, TypeScript, ChakraUI, Google OAuth, Next Auth, ESLint, Prettier, Husky, Lint-Staged, Jest, Testing Library, Commitlint, VSCode, Netlify, SCSS.
Developer experience first:
- β‘ Next.js for Static Site Generator
- π₯ Type checking TypeScript
- β Strict Mode for TypeScript and React 18
- π Linter with ESLint (default NextJS, NextJS Core Web Vitals, Tailwind CSS and Airbnb configuration)
- π Code Formatter with Prettier
- π¦ Husky for Git Hooks
- π« Lint-staged for running linters on Git staged files
- π Lint git commit with Commitlint
- π Write standard compliant commit messages with Commitizen
- π¦Ί Unit Testing with Jest and React Testing Library
- π§ͺ E2E Testing with Cypress
- π‘ Absolute Imports using
@prefix - π VSCode configuration: Debug, Settings, Tasks and extension for PostCSS, ESLint, Prettier, TypeScript, Jest
- π€ SEO metadata, JSON-LD and Open Graph tags with Next SEO
- βοΈ Bundler Analyzer
- π±οΈ One click deployment with Vercel or Netlify (or manual deployment to any hosting services)
- π Include a FREE minimalist theme
- π― Maximize lighthouse score
Built-in feature from Next.js:
- β Minify HTML & SCSS
- π¨ Live reload
- β Cache busting
- Minimal code
- SEO-friendly
- π Production-ready
- Node.js 14+ and yarn 1.22+ (or npm 6+)
Run the following command on your local environment:
git clone https://github.com/paalamugan/nextjs-web-oauth-project.git
cd nextjs-web-oauth-project
yarn installEnvironment configuration before we run the application
-
Option 1
- Create
.env.localfile in the root directory and add the following environment variables:
SITE_URL=http://localhost:3000 # http://localhost:3000 REGRES_API_BASE_URL=https://reqres.in/api # https://reqres.in/api NEXTAUTH_SECRET=secret # random string JWT_SECRET_KEY=secret # random string NEXTAUTH_DEBUG=false # true or false MONGODB_URI=mongodb://admin:adminpassword@localhost:27017/web-oauth # mongodb://admin:adminpassword@localhost:27017/web-oauth GOOGLE_CLIENT_ID=<replace-your-google-client-id> # google client id GOOGLE_CLIENT_SECRET=<replace-your-google-client-secret> # google client secret
- Create
-
Option 2
- Copy .env.example to .env.local and replace the values like above.
cp -rf .env.example .env.local
Make sure you have MongoDB installed and running on your local environment.
- If not then, please use the below command to run mongodb server before run the
yarn dev.
docker-compose up -d web-oauth-mongodbThen, you can run locally in development mode with live reload:
yarn devOpen http://localhost:3000 with our favorite browser to see our project.
Before run the below command, We need to have docker installed in our local machine, if not please install it from here.
docker-compose up -dRun Docker Compose with our custom environment file path using below command, by default it will use .env file or environment variables that we used inside docker-compose.yml file.
docker-compose --env-file .env.local up -d.
βββ README.md # README file
βββ __mocks__ # Mocks for testing
βββ .github # GitHub folder
βββ .husky # Husky configuration
βββ .vscode # VSCode configuration
βββ public # Public assets folder
βββ cypress # Cypress folder e2e testing
βββ db # Init db configuration for docker-compose.yml
βββ msw # Mock Service Worker folder
βββ src
β βββ __tests__ # Unit tests folder
| βββ api-helper # API helper folder
β βββ components # React components folder
β βββ constants # Constants folder
β βββ error-handlers # Error handlers folder
β βββ hooks # React hooks folder
β βββ icons # Icons folder
β βββ layouts # Layouts components
β βββ lib # Library folder
β βββ page-components # Nextjs Page components folder
β βββ pages # Next JS Pages
β βββ pages.test # Next JS Pages tests (this avoid test to treated as a Next.js pages)
β βββ providers # Providers folder
β βββ redux # Redux folder
β βββ styles # Global SCSS Styles folder
β βββ templates # Default template
β βββ utils # Utility functions
βββ test-utils # Test utils folder
βββ typings # Additional Typescript typings
βββ .env.example # Environment variables example
βββ .eslintrc # ESLint configuration
βββ Dockerfile # Dockerfile for production
βββ docker-compose.yml # Docker compose configuration
βββ commitlint.config.js # Commitlint configuration
βββ cypress.config.js # Cypress configuration
βββ tailwind.config.js # Tailwind CSS configuration
βββ tsconfig.json # TypeScript configurationYou can see the results locally in production mode with:
yarn build
yarn startDockerfile is available for production deployment. You can build the image with:
docker build -t web-oauth-app:latest .You can create an optimized production build with:
yarn build-prodNow, Our app is ready to be deployed. All generated files are located at out folder, which you can deploy with any hosting service.
All tests are co-located with the source code inside the same directory. So, it makes it easier to find them. Unfortunately, it is not possible with the pages folder which is used by Next.js for routing. So, what is why we have a pages.test folder to write tests from files located in pages folder.
Deploy this Web OAuth on Vercel in one click:
If you are VSCode users, you can have a better integration with VSCode by installing the suggested extension in .vscode/extension.json. The starter code comes up with Settings for a seamless integration with VSCode. The Debug configuration is also provided for frontend and backend debugging experience.
With the plugins installed on your VSCode, ESLint and Prettier can automatically fix the code and show you the errors. Same goes for testing, you can install VSCode Jest extension to automatically run your tests and it also show the code coverage in context.
Pro tips: if you need a project wide type checking with TypeScript, you can run a build with Cmd + Shift + B on Mac.
- Generate base64 secret key with below command
openssl rand -base64 32