๐ 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 install
Environment configuration before we run the application
-
Option 1
- Create
.env.local
file 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-mongodb
Then, you can run locally in development mode with live reload:
yarn dev
Open 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 -d
Run 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 configuration
You can see the results locally in production mode with:
yarn build
yarn start
Dockerfile 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-prod
Now, 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