Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/paalamugan/nextjs-web-oauth-project

Web OAuth Project using ChakraUI, SCSS, Next.js, React, Redux, Redux Toolkit, TypeScript, and more.
https://github.com/paalamugan/nextjs-web-oauth-project

boilerplate chakra-ui chakra-ui-react commitlint cypress docker-compose dockerfile eslint-config github-actions jestjs msw nextjs react redux redux-toolkit tailwindcss typescript vercel

Last synced: about 1 month ago
JSON representation

Web OAuth Project using ChakraUI, SCSS, Next.js, React, Redux, Redux Toolkit, TypeScript, and more.

Awesome Lists containing this project

README

        

# Web OAuth Project

๐Ÿš€ Web OAuth โšก๏ธ Using with Next.js, TypeScript, ChakraUI, Google OAuth, Next Auth, ESLint, Prettier, Husky, Lint-Staged, Jest, Testing Library, Commitlint, VSCode, Netlify, SCSS.

### Features

Developer experience first:

- โšก [Next.js](https://nextjs.org) for Static Site Generator
- ๐Ÿ”ฅ Type checking [TypeScript](https://www.typescriptlang.org)
- โœ… Strict Mode for TypeScript and React 18
- ๐Ÿ“ Linter with [ESLint](https://eslint.org) (default NextJS, NextJS Core Web Vitals, Tailwind CSS and Airbnb configuration)
- ๐Ÿ’– Code Formatter with [Prettier](https://prettier.io)
- ๐ŸฆŠ 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](https://www.npmjs.com/package/@next/bundle-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

### Philosophy

- Minimal code
- SEO-friendly
- ๐Ÿš€ Production-ready

### Requirements

- Node.js 14+ and yarn 1.22+ (or npm 6+)

### Environment Variables

### Getting started

Run the following command on your local environment:

```shell
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:

```shell
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= # google client id
GOOGLE_CLIENT_SECRET= # google client secret
```

- Option 2

- Copy .env.example to .env.local and replace the values like above.

```shell
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`.

```shell
docker-compose up -d web-oauth-mongodb
```

Then, you can run locally in development mode with live reload:

```shell
yarn dev
```

Open http://localhost:3000 with our favorite browser to see our project.

### Run on application using docker-compose cli (Optional)

Before run the below command, We need to have docker installed in our local machine, if not please install it from [here](https://docs.docker.com/get-docker/).

```shell
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.

```shell
docker-compose --env-file .env.local up -d
```

### Folder Structure

```shell
.
โ”œโ”€โ”€ 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
```

### Deploy to production

You can see the results locally in production mode with:

```shell
yarn build
yarn start
```

Dockerfile is available for production deployment. You can build the image with:

```shell
docker build -t web-oauth-app:latest .
```

You can create an optimized production build with:

```shell
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.

### Testing

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 to Vercel

Deploy this Web OAuth on Vercel in one click:

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/paalamugan/nextjs-web-oauth-project)

### VSCode information (optional)

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.

### Tips

- Generate base64 secret key with below command
```sh
openssl rand -base64 32
```