├── .gitignore ├── README.md ├── keycloak.http ├── keycloak └── docker-compose.yaml ├── nest ├── .docker │ └── mysql │ │ └── Dockerfile ├── .env ├── .eslintrc.js ├── .gitignore ├── .prettierrc ├── Dockerfile ├── README.md ├── api.http ├── docker-compose.yaml ├── entrypoint.sh ├── generate-pass.js ├── jwt.ts ├── nest-cli.json ├── package-lock.json ├── package.json ├── src │ ├── app.controller.spec.ts │ ├── app.controller.ts │ ├── app.module.ts │ ├── app.service.ts │ ├── auth │ │ ├── auth.module.ts │ │ ├── auth │ │ │ ├── auth.controller.spec.ts │ │ │ ├── auth.controller.ts │ │ │ ├── auth.service.spec.ts │ │ │ ├── auth.service.ts │ │ │ └── jwt.guard.ts │ │ ├── jwt-strategy │ │ │ ├── jwt-strategy.service.spec.ts │ │ │ └── jwt-strategy.service.ts │ │ ├── role.decorator.ts │ │ ├── role.guard.spec.ts │ │ └── role.guard.ts │ ├── main.ts │ ├── tenant │ │ ├── tenant.guard.spec.ts │ │ ├── tenant.guard.ts │ │ ├── tenant.module.ts │ │ └── tenant │ │ │ ├── tenant.service.spec.ts │ │ │ └── tenant.service.ts │ └── transactions │ │ ├── dto │ │ ├── create-transaction.dto.ts │ │ └── update-transaction.dto.ts │ │ ├── entities │ │ └── transaction.entity.ts │ │ ├── transactions.controller.spec.ts │ │ ├── transactions.controller.ts │ │ ├── transactions.module.ts │ │ ├── transactions.service.spec.ts │ │ └── transactions.service.ts ├── test │ ├── app.e2e-spec.ts │ └── jest-e2e.json ├── tsconfig.build.json └── tsconfig.json └── next.js ├── .eslintrc.json ├── .gitignore ├── .vscode └── settings.json ├── Dockerfile ├── README.md ├── docker-compose.yaml ├── entrypoint.sh ├── jwt.drawio ├── next-env.d.ts ├── next.config.js ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── silent-check-sso.html └── vercel.svg ├── src ├── hof │ └── withAuth.tsx ├── hooks │ └── useAuthHttp.ts ├── pages │ ├── _app.tsx │ ├── api │ │ └── hello.ts │ ├── index.tsx │ ├── login.tsx │ ├── pagina1.tsx │ └── private.tsx ├── styles │ └── LoginPage.module.css └── util │ ├── auth.ts │ ├── cookies.ts │ └── http.ts └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | .history/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Imersão Full Stack && Full Cycle](https://events-fullcycle.s3.amazonaws.com/events-fullcycle/static/site/img/grupo_4417.png) 2 | 3 | Participe gratuitamente: https://imersao.fullcycle.com.br/ 4 | 5 | ## Sobre o repositório 6 | Esse repositório contém o código-fonte ministrado nas aulas 7 | 8 | * Aplicações Multi-tenancy usando Nest.js e Keycloak: [https://www.youtube.com/watch?v=6vu5SkEMG-w](https://www.youtube.com/watch?v=6vu5SkEMG-w) 9 | 10 | * Usando Keycloak para autenticar aplicações Next.js e Nest.js [https://www.youtube.com/watch?v=A3ZItE_sqOA](https://www.youtube.com/watch?v=A3ZItE_sqOA) 11 | 12 | ## Rodar as aplicações 13 | 14 | O Nest.js e Next.js dependem do Keycloak, por isso é necessário subir o Keycloak com o comando `docker-compose up`. 15 | 16 | Veja a 1ª primeira aula para configurar corretamente o Keycloak. 17 | 18 | Suba depois o Nest.js e depois o Next.js, ambos com o comando `docker-compose up`. 19 | 20 | Execute os comandos: 21 | 22 | ```bash 23 | docker-compose up 24 | ``` 25 | 26 | Acesse no browser http://localhost:3001/login. 27 | 28 | -------------------------------------------------------------------------------- /keycloak.http: -------------------------------------------------------------------------------- 1 | POST http://localhost:8080/auth/realms/fullcycle/protocol/openid-connect/token 2 | Content-Type: application/x-www-form-urlencoded 3 | 4 | client_id=nest 5 | &client_secret=625baf8d-2be8-4850-95cc-ec19c0be2752 6 | &grant_type=password 7 | &username=user1@user.com 8 | &password=123456 9 | 10 | 11 | ### 12 | GET http://localhost:8080/auth/realms/fullcycle/protocol/openid-connect/userinfo 13 | Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJYcG5CelVmSWtRMkprT3M0SHN5RmtBcmJsNGUwSGNHbEM0SklfdDM4MUtVIn0.eyJleHAiOjE2MzEyMzI0NDcsImlhdCI6MTYzMTE5NjQ0NywianRpIjoiNDJhOWFhYjUtNzYyMi00NGI2LWI1NzQtNDc4NWRlODZlZjYzIiwiaXNzIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgwL2F1dGgvcmVhbG1zL2Z1bGxjeWNsZSIsImF1ZCI6ImFjY291bnQiLCJzdWIiOiIxZjJlZjU3Zi01YmMwLTQ5MjMtODYxYy1iZGEyZWJiMWI0YWEiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJuZXN0Iiwic2Vzc2lvbl9zdGF0ZSI6IjU3M2RlNzEwLWIzN2EtNGFiZS05NWNhLTIxNjY2ZjU5NDkyNCIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiaHR0cDovL2xvY2FsaG9zdDozMDAwIl0sInJlYWxtX2FjY2VzcyI6eyJyb2xlcyI6WyJvZmZsaW5lX2FjY2VzcyIsInVtYV9hdXRob3JpemF0aW9uIiwiZGVmYXVsdC1yb2xlcy1mdWxsY3ljbGUiLCJnZXJlbnRlIl19LCJyZXNvdXJjZV9hY2Nlc3MiOnsiYWNjb3VudCI6eyJyb2xlcyI6WyJtYW5hZ2UtYWNjb3VudCIsIm1hbmFnZS1hY2NvdW50LWxpbmtzIiwidmlldy1wcm9maWxlIl19fSwic2NvcGUiOiJlbWFpbCBwcm9maWxlIiwic2lkIjoiNTczZGU3MTAtYjM3YS00YWJlLTk1Y2EtMjE2NjZmNTk0OTI0IiwiZW1haWxfdmVyaWZpZWQiOnRydWUsIm5hbWUiOiJVc2VyMSBMYXN0IG5hbWUiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJ1c2VyMUB1c2VyLmNvbSIsImdpdmVuX25hbWUiOiJVc2VyMSIsImZhbWlseV9uYW1lIjoiTGFzdCBuYW1lIiwiZW1haWwiOiJ1c2VyMUB1c2VyLmNvbSJ9.KtGub0FVBn2dzUmRz34LZlO7UCzwizXxlqIRVL_bar0MmNsG16NvR0F8kQ5YUqEkwfWi9rZ2D7KNhB4h72b2bXQH5_g1swExOzLyguzW7G07wBCGNuZR9UII_rZ6vNsWhBC7606oq8Vf2ohu-1w_TZtpb2kEkZqD9UNDxu02iS9D1fAVZoUwRFBvslyx6RoI1DXyKEUIYgelr5IfEcVdyYDBP7647kX7SwYoJiMTT1WXvapEFKCRWCMQHzowkBXpqRWzCY72kcbN7U4uW6YDFXO-ipvK5Una5c8Zua8jYZM59SvJTcz23MgwRpp1nD8TBqx4xR34o3NKSkrtbhkyGg -------------------------------------------------------------------------------- /keycloak/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | services: 4 | app: 5 | image: jboss/keycloak:15.0.0 6 | environment: 7 | - KEYCLOAK_USER=admin 8 | - KEYCLOAK_PASSWORD=admin 9 | - DB_VENDOR=h2 10 | ports: 11 | - 8080:8080 -------------------------------------------------------------------------------- /nest/.docker/mysql/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mysql:5.7 2 | 3 | RUN usermod -u 1000 mysql -------------------------------------------------------------------------------- /nest/.env: -------------------------------------------------------------------------------- 1 | DB_CONNECTION=mysql 2 | DB_HOST=db 3 | DB_USERNAME=root 4 | DB_PASSWORD=root 5 | DB_DATABASE=fin 6 | DB_PORT=3306 7 | 8 | JWT_SECRET="-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAszV9tJjxZ8LKOVcNRw74ZP5Z/ESEVsYYcVbZWkXupi5tEBoTiy3fEeZNTaQoAYZtsl3QIxD3+PPbNbqVa0JwtMo/qRWHT76f8r42eBbYl0GVhPmFMaP86G5/eOmlN4r4Lb2xNvqy5GlVwnNYd44kxgJfdmuMSdOaSVe9ksMHPVl7mVMoVwBAKbQa/YlukfUKAJwjAwbJZCknrPuQbgf3LKOIpo724eGNmC1yKx0ACvVCudvGuJ79KGeu64hi9wdpJu6SnRJdCn2g+K0uzQ4amIw8f5tUaYKKx2kMRd0FOYmr8Kg6Hda1JC49nbx7l/DbqcnZRDL5kHg8Km9v+6vi5QIDAQAB\n-----END PUBLIC KEY-----" -------------------------------------------------------------------------------- /nest/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | parserOptions: { 4 | project: 'tsconfig.json', 5 | sourceType: 'module', 6 | }, 7 | plugins: ['@typescript-eslint/eslint-plugin'], 8 | extends: [ 9 | 'plugin:@typescript-eslint/recommended', 10 | 'plugin:prettier/recommended', 11 | ], 12 | root: true, 13 | env: { 14 | node: true, 15 | jest: true, 16 | }, 17 | ignorePatterns: ['.eslintrc.js'], 18 | rules: { 19 | '@typescript-eslint/interface-name-prefix': 'off', 20 | '@typescript-eslint/explicit-function-return-type': 'off', 21 | '@typescript-eslint/explicit-module-boundary-types': 'off', 22 | '@typescript-eslint/no-explicit-any': 'off', 23 | }, 24 | }; 25 | -------------------------------------------------------------------------------- /nest/.gitignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist 3 | /node_modules 4 | 5 | # Logs 6 | logs 7 | *.log 8 | npm-debug.log* 9 | pnpm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | lerna-debug.log* 13 | 14 | # OS 15 | .DS_Store 16 | 17 | # Tests 18 | /coverage 19 | /.nyc_output 20 | 21 | # IDEs and editors 22 | /.idea 23 | .project 24 | .classpath 25 | .c9/ 26 | *.launch 27 | .settings/ 28 | *.sublime-workspace 29 | 30 | # IDE - VSCode 31 | .vscode/* 32 | !.vscode/settings.json 33 | !.vscode/tasks.json 34 | !.vscode/launch.json 35 | !.vscode/extensions.json 36 | 37 | .history/ 38 | 39 | .docker/dbdata -------------------------------------------------------------------------------- /nest/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } -------------------------------------------------------------------------------- /nest/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:14.15.4-alpine3.12 2 | 3 | RUN apk add --no-cache bash 4 | 5 | RUN npm install -g @nestjs/cli@8.0.0 6 | 7 | ENV DOCKERIZE_VERSION v0.6.1 8 | RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ 9 | && tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ 10 | && rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz 11 | 12 | USER node 13 | 14 | WORKDIR /home/node/app -------------------------------------------------------------------------------- /nest/README.md: -------------------------------------------------------------------------------- 1 | ![Imersão Full Stack && Full Cycle](https://events-fullcycle.s3.amazonaws.com/events-fullcycle/static/site/img/grupo_4417.png) 2 | 3 | Participe gratuitamente: https://imersao.fullcycle.com.br/ 4 | 5 | ## Sobre o repositório 6 | Esse repositório contém o código-fonte ministrado na aula Nest.js com Autenticação JWT: [https://www.youtube.com/watch?v=SinonmkxRSI](https://www.youtube.com/watch?v=SinonmkxRSI) 7 | 8 | ## Rodar a aplicação 9 | 10 | Execute os comandos: 11 | 12 | ```bash 13 | docker-compose up 14 | ``` 15 | 16 | Acesse no browser http://localhost:3000/login. Use o arquivo `api.http` para testar o JWT. 17 | 18 | -------------------------------------------------------------------------------- /nest/api.http: -------------------------------------------------------------------------------- 1 | POST http://localhost:3000/login 2 | Content-Type: application/json 3 | 4 | { 5 | "username": "user1@user.com", 6 | "password": "123456" 7 | } 8 | 9 | ### 10 | GET http://localhost:3000/test-auth 11 | Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJYcG5CelVmSWtRMkprT3M0SHN5RmtBcmJsNGUwSGNHbEM0SklfdDM4MUtVIn0.eyJleHAiOjE2MzEyMzQzNzQsImlhdCI6MTYzMTE5ODM3NCwianRpIjoiZTAzYjU2ZjYtNTliOS00YWE0LWI2ZGQtYjEyNzc2ZjZlN2Y0IiwiaXNzIjoiaHR0cDovL2hvc3QuZG9ja2VyLmludGVybmFsOjgwODAvYXV0aC9yZWFsbXMvZnVsbGN5Y2xlIiwiYXVkIjoiYWNjb3VudCIsInN1YiI6IjFmMmVmNTdmLTViYzAtNDkyMy04NjFjLWJkYTJlYmIxYjRhYSIsInR5cCI6IkJlYXJlciIsImF6cCI6Im5lc3QiLCJzZXNzaW9uX3N0YXRlIjoiZTZhMjA0YjYtZWJkZS00YzhhLTk1YmEtODkwZDYzYTVhN2MzIiwiYWNyIjoiMSIsImFsbG93ZWQtb3JpZ2lucyI6WyJodHRwOi8vbG9jYWxob3N0OjMwMDAiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbIm9mZmxpbmVfYWNjZXNzIiwidW1hX2F1dGhvcml6YXRpb24iLCJkZWZhdWx0LXJvbGVzLWZ1bGxjeWNsZSIsImdlcmVudGUiXX0sInJlc291cmNlX2FjY2VzcyI6eyJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19LCJzY29wZSI6ImVtYWlsIHByb2ZpbGUiLCJzaWQiOiJlNmEyMDRiNi1lYmRlLTRjOGEtOTViYS04OTBkNjNhNWE3YzMiLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwibmFtZSI6IlVzZXIxIExhc3QgbmFtZSIsInByZWZlcnJlZF91c2VybmFtZSI6InVzZXIxQHVzZXIuY29tIiwiZ2l2ZW5fbmFtZSI6IlVzZXIxIiwiZmFtaWx5X25hbWUiOiJMYXN0IG5hbWUiLCJlbWFpbCI6InVzZXIxQHVzZXIuY29tIn0.Pgs6DdiYhMgFJxmDjSON72ThZGTyjuzt4Q35Ulzkwt44HyhsMXhWdCYvZ7X5F7q8hHUlqhwMN_7_GXKALxe-WtPASsZjewb-DMswKzgKX4dPC6AzPQnXCiAKsyg32o1M5XWzm8w7VdwVJC7RSwj5mn_epkKWRfQa4G4DqGJF-gxM8oxb-vMv7JO52ewVuZd5byA3ZtQZuVFZcjN5yfvOYO6pSSjDCM1t3RXMfRKERPnMWEj0M98mKUijKkq9HArVJEX6sEUEzK-u12a0PXxgiZCj0AWK8UMHi4C9I7PV2QVFGigVGb3_b0qn9MIXOA4MArWMK9Db_Rwr3NX-d4aLmQ 12 | 13 | #https 14 | 15 | #{role: 'user'} 16 | 17 | # requisicao bearer auth -> requisicao para keycloak validar token ---> resposta 18 | 19 | # dupla latencia 20 | 21 | 22 | ### 23 | POST http://localhost:3000/transactions 24 | Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJYcG5CelVmSWtRMkprT3M0SHN5RmtBcmJsNGUwSGNHbEM0SklfdDM4MUtVIn0.eyJleHAiOjE2MzEyMzg4NDYsImlhdCI6MTYzMTIwMjg0NiwianRpIjoiNWY5OTQ2MjktYzY3NS00NTcwLWI5NjMtNDA0NDE1Mjk2OGMxIiwiaXNzIjoiaHR0cDovL2hvc3QuZG9ja2VyLmludGVybmFsOjgwODAvYXV0aC9yZWFsbXMvZnVsbGN5Y2xlIiwiYXVkIjoiYWNjb3VudCIsInN1YiI6IjFmMmVmNTdmLTViYzAtNDkyMy04NjFjLWJkYTJlYmIxYjRhYSIsInR5cCI6IkJlYXJlciIsImF6cCI6Im5lc3QiLCJzZXNzaW9uX3N0YXRlIjoiNTA5YzQ1ODgtYmJiYi00MzI3LTk4MzEtODJhNGQzMzMzMzc3IiwiYWNyIjoiMSIsImFsbG93ZWQtb3JpZ2lucyI6WyJodHRwOi8vbG9jYWxob3N0OjMwMDAiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbIm9mZmxpbmVfYWNjZXNzIiwidW1hX2F1dGhvcml6YXRpb24iLCJkZWZhdWx0LXJvbGVzLWZ1bGxjeWNsZSIsImdlcmVudGUiXX0sInJlc291cmNlX2FjY2VzcyI6eyJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19LCJzY29wZSI6ImVtYWlsIHByb2ZpbGUiLCJzaWQiOiI1MDljNDU4OC1iYmJiLTQzMjctOTgzMS04MmE0ZDMzMzMzNzciLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwibmFtZSI6IlVzZXIxIExhc3QgbmFtZSIsInN1YmRvbWFpbiI6InRlbmFudDEiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJ1c2VyMUB1c2VyLmNvbSIsImdpdmVuX25hbWUiOiJVc2VyMSIsImZhbWlseV9uYW1lIjoiTGFzdCBuYW1lIiwiZW1haWwiOiJ1c2VyMUB1c2VyLmNvbSJ9.es1FiSjOJfiiPNVSBdMZNzeYNBVhkjJw9Gp9-9QsdhyGPtso5DuQfHdeKtod-pRYB9WJshGYOYyKZpMnVfu97L3PHugfhi0xUZ2SdqM5y1VmZQoQQhq5EWgJp_U3geN9w-m6aLQ8sa5G3SWEQRTq8cDmQdXJKZXXVXkScPEUOgSsu9D2gd5EsLXYeHTBih9qs4_gtod8wbYVFcHG77MCFCDlFHuqJT1u4hlZ_1eQn04fAbaSCFzktuP5hxhPadECzwofIghYfA3f9NwQmouycMD_kUoHMeICiL0f8CT0YMwn3ie6tje4tnTnymgE1049TgbtuKyWD3qoixoIEWKBvg 25 | Content-Type: application/json 26 | 27 | { 28 | "payment_date": "2021-01-01", 29 | "name": "Nova conta 1", 30 | "amount": 30 31 | } 32 | 33 | ### 34 | GET http://localhost:3000/transactions 35 | Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJYcG5CelVmSWtRMkprT3M0SHN5RmtBcmJsNGUwSGNHbEM0SklfdDM4MUtVIn0.eyJleHAiOjE2MzEyMzg4NDYsImlhdCI6MTYzMTIwMjg0NiwianRpIjoiNWY5OTQ2MjktYzY3NS00NTcwLWI5NjMtNDA0NDE1Mjk2OGMxIiwiaXNzIjoiaHR0cDovL2hvc3QuZG9ja2VyLmludGVybmFsOjgwODAvYXV0aC9yZWFsbXMvZnVsbGN5Y2xlIiwiYXVkIjoiYWNjb3VudCIsInN1YiI6IjFmMmVmNTdmLTViYzAtNDkyMy04NjFjLWJkYTJlYmIxYjRhYSIsInR5cCI6IkJlYXJlciIsImF6cCI6Im5lc3QiLCJzZXNzaW9uX3N0YXRlIjoiNTA5YzQ1ODgtYmJiYi00MzI3LTk4MzEtODJhNGQzMzMzMzc3IiwiYWNyIjoiMSIsImFsbG93ZWQtb3JpZ2lucyI6WyJodHRwOi8vbG9jYWxob3N0OjMwMDAiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbIm9mZmxpbmVfYWNjZXNzIiwidW1hX2F1dGhvcml6YXRpb24iLCJkZWZhdWx0LXJvbGVzLWZ1bGxjeWNsZSIsImdlcmVudGUiXX0sInJlc291cmNlX2FjY2VzcyI6eyJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19LCJzY29wZSI6ImVtYWlsIHByb2ZpbGUiLCJzaWQiOiI1MDljNDU4OC1iYmJiLTQzMjctOTgzMS04MmE0ZDMzMzMzNzciLCJlbWFpbF92ZXJpZmllZCI6dHJ1ZSwibmFtZSI6IlVzZXIxIExhc3QgbmFtZSIsInN1YmRvbWFpbiI6InRlbmFudDEiLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJ1c2VyMUB1c2VyLmNvbSIsImdpdmVuX25hbWUiOiJVc2VyMSIsImZhbWlseV9uYW1lIjoiTGFzdCBuYW1lIiwiZW1haWwiOiJ1c2VyMUB1c2VyLmNvbSJ9.es1FiSjOJfiiPNVSBdMZNzeYNBVhkjJw9Gp9-9QsdhyGPtso5DuQfHdeKtod-pRYB9WJshGYOYyKZpMnVfu97L3PHugfhi0xUZ2SdqM5y1VmZQoQQhq5EWgJp_U3geN9w-m6aLQ8sa5G3SWEQRTq8cDmQdXJKZXXVXkScPEUOgSsu9D2gd5EsLXYeHTBih9qs4_gtod8wbYVFcHG77MCFCDlFHuqJT1u4hlZ_1eQn04fAbaSCFzktuP5hxhPadECzwofIghYfA3f9NwQmouycMD_kUoHMeICiL0f8CT0YMwn3ie6tje4tnTnymgE1049TgbtuKyWD3qoixoIEWKBvg 36 | 37 | -------------------------------------------------------------------------------- /nest/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | app: 5 | build: . 6 | entrypoint: dockerize -wait tcp://db:3306 -timeout 40s ./entrypoint.sh 7 | ports: 8 | - 3000:3000 9 | volumes: 10 | - .:/home/node/app 11 | extra_hosts: 12 | - "host.docker.internal:172.17.0.1" 13 | depends_on: 14 | - db 15 | 16 | db: 17 | build: ./.docker/mysql 18 | restart: always 19 | tty: true 20 | volumes: 21 | - ./.docker/dbdata:/var/lib/mysql 22 | environment: 23 | - MYSQL_DATABASE=fin 24 | - MYSQL_ROOT_PASSWORD=root 25 | 26 | # //etc/hosts 27 | # //C:\Windows\system32\drivers\etc\hosts 28 | 29 | # 127.0.0.1 host.docker.internal 30 | 31 | -------------------------------------------------------------------------------- /nest/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | npm install 4 | 5 | npm run start:dev -------------------------------------------------------------------------------- /nest/generate-pass.js: -------------------------------------------------------------------------------- 1 | const bcrypt = require('bcrypt'); 2 | const saltRounds = 10; 3 | const password = process.argv.slice(2)[0]; 4 | 5 | bcrypt.genSalt(saltRounds, function (err, salt) { 6 | bcrypt.hash(password, salt, function (err, hash) { 7 | console.log(hash); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /nest/jwt.ts: -------------------------------------------------------------------------------- 1 | const base64Url = require('base64url'); 2 | 3 | const header = { 4 | alg: 'HS256', 5 | typ: 'JWT', 6 | }; 7 | 8 | const payload = { 9 | username: 'user1@user.com', 10 | name: 'Luiz Carlos', 11 | exp: new Date().getTime(), //timestamp 12 | }; 13 | 14 | const headerEncoded = base64Url.encode(JSON.stringify(header)); 15 | const payloadEncoded = base64Url.encode(JSON.stringify(payload)); 16 | 17 | console.log(headerEncoded, payloadEncoded); 18 | 19 | const key = 'abcd123456'; 20 | 21 | //certificado - chave privada e outro publica 22 | 23 | const crypt = require('crypto'); 24 | 25 | const signature = crypt 26 | .createHmac('sha256', key) 27 | .update(`${headerEncoded}.${payloadEncoded}`) 28 | .digest('bin'); 29 | 30 | console.log(`${headerEncoded}.${payloadEncoded}.${base64Url.encode(signature)}`); -------------------------------------------------------------------------------- /nest/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "collection": "@nestjs/schematics", 3 | "sourceRoot": "src" 4 | } 5 | -------------------------------------------------------------------------------- /nest/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "live-nest-auth", 3 | "version": "0.0.1", 4 | "description": "", 5 | "author": "", 6 | "private": true, 7 | "license": "UNLICENSED", 8 | "scripts": { 9 | "prebuild": "rimraf dist", 10 | "build": "nest build", 11 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", 12 | "start": "nest start", 13 | "start:dev": "nest start --watch", 14 | "start:debug": "nest start --debug --watch", 15 | "start:prod": "node dist/main", 16 | "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", 17 | "test": "jest", 18 | "test:watch": "jest --watch", 19 | "test:cov": "jest --coverage", 20 | "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", 21 | "test:e2e": "jest --config ./test/jest-e2e.json" 22 | }, 23 | "dependencies": { 24 | "@nestjs/axios": "0.0.1", 25 | "@nestjs/common": "^8.0.0", 26 | "@nestjs/config": "^1.0.1", 27 | "@nestjs/core": "^8.0.0", 28 | "@nestjs/jwt": "^8.0.0", 29 | "@nestjs/mapped-types": "*", 30 | "@nestjs/passport": "^8.0.1", 31 | "@nestjs/platform-express": "^8.0.0", 32 | "@nestjs/sequelize": "^8.0.0", 33 | "base64url": "^3.0.1", 34 | "bcrypt": "^5.0.1", 35 | "mysql2": "^2.3.0", 36 | "passport": "^0.4.1", 37 | "passport-jwt": "^4.0.0", 38 | "reflect-metadata": "^0.1.13", 39 | "rimraf": "^3.0.2", 40 | "rxjs": "^7.2.0", 41 | "sequelize": "^6.6.5", 42 | "sequelize-typescript": "^2.1.0" 43 | }, 44 | "devDependencies": { 45 | "@nestjs/cli": "^8.0.0", 46 | "@nestjs/schematics": "^8.0.0", 47 | "@nestjs/testing": "^8.0.0", 48 | "@types/express": "^4.17.13", 49 | "@types/jest": "^26.0.24", 50 | "@types/node": "^16.0.0", 51 | "@types/passport": "^1.0.7", 52 | "@types/passport-jwt": "^3.0.6", 53 | "@types/sequelize": "^4.28.10", 54 | "@types/supertest": "^2.0.11", 55 | "@typescript-eslint/eslint-plugin": "^4.28.2", 56 | "@typescript-eslint/parser": "^4.28.2", 57 | "eslint": "^7.30.0", 58 | "eslint-config-prettier": "^8.3.0", 59 | "eslint-plugin-prettier": "^3.4.0", 60 | "jest": "27.0.6", 61 | "prettier": "^2.3.2", 62 | "supertest": "^6.1.3", 63 | "ts-jest": "^27.0.3", 64 | "ts-loader": "^9.2.3", 65 | "ts-node": "^10.0.0", 66 | "tsconfig-paths": "^3.10.1", 67 | "typescript": "^4.3.5" 68 | }, 69 | "jest": { 70 | "moduleFileExtensions": [ 71 | "js", 72 | "json", 73 | "ts" 74 | ], 75 | "rootDir": "src", 76 | "testRegex": ".*\\.spec\\.ts$", 77 | "transform": { 78 | "^.+\\.(t|j)s$": "ts-jest" 79 | }, 80 | "collectCoverageFrom": [ 81 | "**/*.(t|j)s" 82 | ], 83 | "coverageDirectory": "../coverage", 84 | "testEnvironment": "node" 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /nest/src/app.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { AppController } from './app.controller'; 3 | import { AppService } from './app.service'; 4 | 5 | describe('AppController', () => { 6 | let appController: AppController; 7 | 8 | beforeEach(async () => { 9 | const app: TestingModule = await Test.createTestingModule({ 10 | controllers: [AppController], 11 | providers: [AppService], 12 | }).compile(); 13 | 14 | appController = app.get(AppController); 15 | }); 16 | 17 | describe('root', () => { 18 | it('should return "Hello World!"', () => { 19 | expect(appController.getHello()).toBe('Hello World!'); 20 | }); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /nest/src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get } from '@nestjs/common'; 2 | import { AppService } from './app.service'; 3 | 4 | @Controller() 5 | export class AppController { 6 | // 7 | constructor(private readonly appService: AppService) {} 8 | 9 | @Get() 10 | getHello(): string { 11 | return this.appService.getHello(); 12 | } 13 | 14 | @Get('test') 15 | metodo1(){ 16 | return 'qualquer coisa'; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /nest/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { ConfigModule } from '@nestjs/config'; 3 | import { SequelizeModule } from '@nestjs/sequelize'; 4 | import { AppController } from './app.controller'; 5 | import { AppService } from './app.service'; 6 | import { AuthModule } from './auth/auth.module'; 7 | import { Transaction } from './transactions/entities/transaction.entity'; 8 | import { TransactionsModule } from './transactions/transactions.module'; 9 | import { TenantModule } from './tenant/tenant.module'; 10 | //decorator - Javascript - Ecmascript 7 11 | 12 | @Module({ 13 | imports: [ 14 | ConfigModule.forRoot({ 15 | isGlobal: true, 16 | }), 17 | SequelizeModule.forRoot({ 18 | dialect: process.env.DB_CONNECTION as any, 19 | host: process.env.DB_HOST, 20 | port: parseInt(process.env.DB_PORT), 21 | username: process.env.DB_USERNAME, 22 | password: process.env.DB_PASSWORD, 23 | database: process.env.DB_DATABASE, 24 | models: [Transaction], 25 | autoLoadModels: true, 26 | synchronize: true, 27 | sync: { 28 | alter: true, 29 | // force: true 30 | }, 31 | }), 32 | AuthModule, 33 | TransactionsModule, 34 | TenantModule, 35 | ], 36 | controllers: [AppController], 37 | providers: [AppService], 38 | }) 39 | export class AppModule {} 40 | -------------------------------------------------------------------------------- /nest/src/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class AppService { 5 | getHello(): string { 6 | return 'Hello World!'; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /nest/src/auth/auth.module.ts: -------------------------------------------------------------------------------- 1 | import { HttpModule } from '@nestjs/axios'; 2 | import { Module } from '@nestjs/common'; 3 | import { ConfigModule } from '@nestjs/config'; 4 | import { JwtModule } from '@nestjs/jwt'; 5 | import { AuthController } from './auth/auth.controller'; 6 | import { AuthService } from './auth/auth.service'; 7 | import { JwtStrategyService } from './jwt-strategy/jwt-strategy.service'; 8 | 9 | @Module({ 10 | imports: [ 11 | HttpModule, 12 | JwtModule.register({ 13 | secret: 'abcd123456', 14 | signOptions: { 15 | expiresIn: '60s', 16 | }, 17 | }), 18 | ], 19 | controllers: [AuthController], 20 | providers: [AuthService, JwtStrategyService], 21 | }) 22 | export class AuthModule {} 23 | -------------------------------------------------------------------------------- /nest/src/auth/auth/auth.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { AuthController } from './auth.controller'; 3 | 4 | describe('AuthController', () => { 5 | let controller: AuthController; 6 | 7 | beforeEach(async () => { 8 | const module: TestingModule = await Test.createTestingModule({ 9 | controllers: [AuthController], 10 | }).compile(); 11 | 12 | controller = module.get(AuthController); 13 | }); 14 | 15 | it('should be defined', () => { 16 | expect(controller).toBeDefined(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /nest/src/auth/auth/auth.controller.ts: -------------------------------------------------------------------------------- 1 | import { RoleGuard } from './../role.guard'; 2 | import { JwtGuard } from './jwt.guard'; 3 | import { Body, Controller, Get, Post, Req, UseGuards } from '@nestjs/common'; 4 | import { AuthService } from './auth.service'; 5 | import { Role } from '../role.decorator'; 6 | 7 | @Controller() 8 | export class AuthController { 9 | constructor(private authService: AuthService) {} 10 | 11 | @Post('login') 12 | login(@Body() body) { 13 | return this.authService.login(body.username, body.password); 14 | } 15 | 16 | //@Role('admin') 17 | @UseGuards(JwtGuard) 18 | @Get('test-auth') 19 | test(@Req() req) { 20 | console.log(req.user); 21 | return { 22 | name: 'Luiz Carlos', 23 | }; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /nest/src/auth/auth/auth.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { AuthService } from './auth.service'; 3 | 4 | describe('AuthService', () => { 5 | let service: AuthService; 6 | 7 | beforeEach(async () => { 8 | const module: TestingModule = await Test.createTestingModule({ 9 | providers: [AuthService], 10 | }).compile(); 11 | 12 | service = module.get(AuthService); 13 | }); 14 | 15 | it('should be defined', () => { 16 | expect(service).toBeDefined(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /nest/src/auth/auth/auth.service.ts: -------------------------------------------------------------------------------- 1 | import { HttpService } from '@nestjs/axios'; 2 | import { Injectable } from '@nestjs/common'; 3 | import { firstValueFrom } from 'rxjs'; 4 | //Reactive X 5 | @Injectable() 6 | export class AuthService { 7 | constructor(private http: HttpService) {} 8 | 9 | async login(username: string, password: string) { 10 | const { data } = await firstValueFrom( 11 | this.http.post( 12 | 'http://host.docker.internal:8080/auth/realms/fullcycle/protocol/openid-connect/token', 13 | new URLSearchParams({ 14 | client_id: 'nest', 15 | client_secret: '57441e32-b353-40a5-81e3-75cda25e6b5e', 16 | grant_type: 'password', 17 | username, 18 | password, 19 | }), 20 | ), 21 | ); 22 | return data; 23 | } 24 | } 25 | //auth0 - jsonwebtoken 26 | 27 | // client_id=nest 28 | // &client_secret=625baf8d-2be8-4850-95cc-ec19c0be2752 29 | // &grant_type=password 30 | // &username=user1@user.com 31 | // &password=123456 32 | -------------------------------------------------------------------------------- /nest/src/auth/auth/jwt.guard.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { AuthGuard } from '@nestjs/passport'; 3 | 4 | @Injectable() 5 | export class JwtGuard extends AuthGuard('jwt') {} 6 | -------------------------------------------------------------------------------- /nest/src/auth/jwt-strategy/jwt-strategy.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { JwtStrategyService } from './jwt-strategy.service'; 3 | 4 | describe('JwtStrategyService', () => { 5 | let service: JwtStrategyService; 6 | 7 | beforeEach(async () => { 8 | const module: TestingModule = await Test.createTestingModule({ 9 | providers: [JwtStrategyService], 10 | }).compile(); 11 | 12 | service = module.get(JwtStrategyService); 13 | }); 14 | 15 | it('should be defined', () => { 16 | expect(service).toBeDefined(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /nest/src/auth/jwt-strategy/jwt-strategy.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import { ConfigService } from '@nestjs/config'; 3 | import { PassportStrategy } from '@nestjs/passport'; 4 | import { ExtractJwt, Strategy } from 'passport-jwt'; 5 | 6 | @Injectable() 7 | export class JwtStrategyService extends PassportStrategy(Strategy, 'jwt') { 8 | constructor(configService: ConfigService) { 9 | super({ 10 | jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), 11 | ignoreExpiration: false, 12 | secretOrKey: configService.get('JWT_SECRET'), 13 | }); 14 | } 15 | 16 | async validate(payload) { 17 | return payload; //delimito as informacoes do user 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /nest/src/auth/role.decorator.ts: -------------------------------------------------------------------------------- 1 | import { SetMetadata } from '@nestjs/common'; 2 | 3 | export const Role = (role: string) => { 4 | return SetMetadata('role', role); 5 | }; 6 | -------------------------------------------------------------------------------- /nest/src/auth/role.guard.spec.ts: -------------------------------------------------------------------------------- 1 | import { RoleGuard } from './role.guard'; 2 | 3 | describe('RoleGuard', () => { 4 | it('should be defined', () => { 5 | expect(new RoleGuard()).toBeDefined(); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /nest/src/auth/role.guard.ts: -------------------------------------------------------------------------------- 1 | import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'; 2 | import { Reflector } from '@nestjs/core'; 3 | import { Observable } from 'rxjs'; 4 | 5 | @Injectable() 6 | export class RoleGuard implements CanActivate { 7 | constructor(private reflector: Reflector) {} 8 | 9 | canActivate( 10 | context: ExecutionContext, 11 | ): boolean | Promise | Observable { 12 | const role = this.reflector.get('role', context.getHandler()); 13 | if (!role) { 14 | return true; 15 | } 16 | const request = context.switchToHttp().getRequest(); 17 | const user = request.user; 18 | return user.role == role; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /nest/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(3000); 7 | } 8 | bootstrap(); 9 | -------------------------------------------------------------------------------- /nest/src/tenant/tenant.guard.spec.ts: -------------------------------------------------------------------------------- 1 | import { TenantGuard } from './tenant.guard'; 2 | 3 | describe('TenantGuard', () => { 4 | it('should be defined', () => { 5 | expect(new TenantGuard()).toBeDefined(); 6 | }); 7 | }); 8 | -------------------------------------------------------------------------------- /nest/src/tenant/tenant.guard.ts: -------------------------------------------------------------------------------- 1 | import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'; 2 | import { Observable } from 'rxjs'; 3 | import { TenantService } from './tenant/tenant.service'; 4 | 5 | @Injectable() 6 | export class TenantGuard implements CanActivate { 7 | 8 | constructor(private tenantService: TenantService){ 9 | 10 | } 11 | 12 | canActivate( 13 | context: ExecutionContext, 14 | ): boolean | Promise | Observable { 15 | const request = context.switchToHttp().getRequest(); 16 | const subdomain = request.user.subdomain; 17 | this.tenantService.subdomain = subdomain; 18 | return true; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /nest/src/tenant/tenant.module.ts: -------------------------------------------------------------------------------- 1 | import { TenantGuard } from './tenant.guard'; 2 | import { Global, Module } from '@nestjs/common'; 3 | import { TenantService } from './tenant/tenant.service'; 4 | 5 | @Global() 6 | @Module({ 7 | providers: [TenantService, TenantGuard], 8 | exports: [TenantService], 9 | }) 10 | export class TenantModule {} 11 | -------------------------------------------------------------------------------- /nest/src/tenant/tenant/tenant.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { TenantService } from './tenant.service'; 3 | 4 | describe('TenantService', () => { 5 | let service: TenantService; 6 | 7 | beforeEach(async () => { 8 | const module: TestingModule = await Test.createTestingModule({ 9 | providers: [TenantService], 10 | }).compile(); 11 | 12 | service = module.get(TenantService); 13 | }); 14 | 15 | it('should be defined', () => { 16 | expect(service).toBeDefined(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /nest/src/tenant/tenant/tenant.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | 3 | @Injectable() 4 | export class TenantService { 5 | subdomain: string 6 | } 7 | -------------------------------------------------------------------------------- /nest/src/transactions/dto/create-transaction.dto.ts: -------------------------------------------------------------------------------- 1 | export class CreateTransactionDto {} 2 | -------------------------------------------------------------------------------- /nest/src/transactions/dto/update-transaction.dto.ts: -------------------------------------------------------------------------------- 1 | import { PartialType } from '@nestjs/mapped-types'; 2 | import { CreateTransactionDto } from './create-transaction.dto'; 3 | 4 | export class UpdateTransactionDto extends PartialType(CreateTransactionDto) {} 5 | -------------------------------------------------------------------------------- /nest/src/transactions/entities/transaction.entity.ts: -------------------------------------------------------------------------------- 1 | import { Model, Column, Table } from 'sequelize-typescript'; 2 | 3 | @Table({ tableName: 'transactions' }) 4 | export class Transaction extends Model { 5 | @Column 6 | payment_date: Date; 7 | 8 | @Column 9 | name: string; 10 | 11 | @Column 12 | amount: number; 13 | 14 | @Column 15 | subdomain: string; 16 | } 17 | -------------------------------------------------------------------------------- /nest/src/transactions/transactions.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { TransactionsController } from './transactions.controller'; 3 | import { TransactionsService } from './transactions.service'; 4 | 5 | describe('TransactionsController', () => { 6 | let controller: TransactionsController; 7 | 8 | beforeEach(async () => { 9 | const module: TestingModule = await Test.createTestingModule({ 10 | controllers: [TransactionsController], 11 | providers: [TransactionsService], 12 | }).compile(); 13 | 14 | controller = module.get(TransactionsController); 15 | }); 16 | 17 | it('should be defined', () => { 18 | expect(controller).toBeDefined(); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /nest/src/transactions/transactions.controller.ts: -------------------------------------------------------------------------------- 1 | import { TenantGuard } from './../tenant/tenant.guard'; 2 | import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common'; 3 | import { TransactionsService } from './transactions.service'; 4 | import { CreateTransactionDto } from './dto/create-transaction.dto'; 5 | import { UpdateTransactionDto } from './dto/update-transaction.dto'; 6 | import { JwtGuard } from 'src/auth/auth/jwt.guard'; 7 | 8 | @Controller('transactions') 9 | export class TransactionsController { 10 | constructor(private readonly transactionsService: TransactionsService) {} 11 | 12 | @UseGuards(JwtGuard, TenantGuard) 13 | @Post() 14 | create(@Body() createTransactionDto: CreateTransactionDto) { 15 | return this.transactionsService.create(createTransactionDto); 16 | } 17 | 18 | @UseGuards(JwtGuard, TenantGuard) 19 | @Get() 20 | findAll() { 21 | return this.transactionsService.findAll(); 22 | } 23 | 24 | @Get(':id') 25 | findOne(@Param('id') id: string) { 26 | return this.transactionsService.findOne(+id); 27 | } 28 | 29 | @Patch(':id') 30 | update(@Param('id') id: string, @Body() updateTransactionDto: UpdateTransactionDto) { 31 | return this.transactionsService.update(+id, updateTransactionDto); 32 | } 33 | 34 | @Delete(':id') 35 | remove(@Param('id') id: string) { 36 | return this.transactionsService.remove(+id); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /nest/src/transactions/transactions.module.ts: -------------------------------------------------------------------------------- 1 | import { SequelizeModule } from '@nestjs/sequelize'; 2 | import { Module } from '@nestjs/common'; 3 | import { TransactionsService } from './transactions.service'; 4 | import { TransactionsController } from './transactions.controller'; 5 | import { Transaction } from './entities/transaction.entity'; 6 | 7 | @Module({ 8 | imports: [SequelizeModule.forFeature([Transaction])], 9 | controllers: [TransactionsController], 10 | providers: [TransactionsService], 11 | }) 12 | export class TransactionsModule {} 13 | -------------------------------------------------------------------------------- /nest/src/transactions/transactions.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { TransactionsService } from './transactions.service'; 3 | 4 | describe('TransactionsService', () => { 5 | let service: TransactionsService; 6 | 7 | beforeEach(async () => { 8 | const module: TestingModule = await Test.createTestingModule({ 9 | providers: [TransactionsService], 10 | }).compile(); 11 | 12 | service = module.get(TransactionsService); 13 | }); 14 | 15 | it('should be defined', () => { 16 | expect(service).toBeDefined(); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /nest/src/transactions/transactions.service.ts: -------------------------------------------------------------------------------- 1 | import { TenantService } from './../tenant/tenant/tenant.service'; 2 | import { Injectable } from '@nestjs/common'; 3 | import { InjectModel } from '@nestjs/sequelize'; 4 | import { CreateTransactionDto } from './dto/create-transaction.dto'; 5 | import { UpdateTransactionDto } from './dto/update-transaction.dto'; 6 | import { Transaction } from './entities/transaction.entity'; 7 | 8 | @Injectable() 9 | export class TransactionsService { 10 | constructor( 11 | @InjectModel(Transaction) private transactionModel: typeof Transaction, 12 | private tenantService: TenantService 13 | ) {} 14 | 15 | create(createTransactionDto: CreateTransactionDto) { 16 | return this.transactionModel.create({ 17 | ...createTransactionDto, 18 | subdomain: this.tenantService.subdomain 19 | }); 20 | } 21 | 22 | findAll() { 23 | console.log(this.tenantService.subdomain); 24 | return this.transactionModel.findAll({ 25 | where: { 26 | subdomain: this.tenantService.subdomain 27 | } 28 | }); 29 | } 30 | 31 | findOne(id: number) { 32 | return `This action returns a #${id} transaction`; 33 | } 34 | 35 | update(id: number, updateTransactionDto: UpdateTransactionDto) { 36 | return `This action updates a #${id} transaction`; 37 | } 38 | 39 | remove(id: number) { 40 | return `This action removes a #${id} transaction`; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /nest/test/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, TestingModule } from '@nestjs/testing'; 2 | import { INestApplication } from '@nestjs/common'; 3 | import * as request from 'supertest'; 4 | import { AppModule } from './../src/app.module'; 5 | 6 | describe('AppController (e2e)', () => { 7 | let app: INestApplication; 8 | 9 | beforeEach(async () => { 10 | const moduleFixture: TestingModule = await Test.createTestingModule({ 11 | imports: [AppModule], 12 | }).compile(); 13 | 14 | app = moduleFixture.createNestApplication(); 15 | await app.init(); 16 | }); 17 | 18 | it('/ (GET)', () => { 19 | return request(app.getHttpServer()) 20 | .get('/') 21 | .expect(200) 22 | .expect('Hello World!'); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /nest/test/jest-e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": ["js", "json", "ts"], 3 | "rootDir": ".", 4 | "testEnvironment": "node", 5 | "testRegex": ".e2e-spec.ts$", 6 | "transform": { 7 | "^.+\\.(t|j)s$": "ts-jest" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /nest/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /nest/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "declaration": true, 5 | "removeComments": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": true, 9 | "target": "es2017", 10 | "sourceMap": true, 11 | "outDir": "./dist", 12 | "baseUrl": "./", 13 | "incremental": true, 14 | "skipLibCheck": true 15 | }, 16 | "include": ["src"] 17 | } 18 | -------------------------------------------------------------------------------- /next.js/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /next.js/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | 27 | # local env files 28 | .env.local 29 | .env.development.local 30 | .env.test.local 31 | .env.production.local 32 | 33 | # vercel 34 | .vercel 35 | -------------------------------------------------------------------------------- /next.js/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "workbench.colorCustomizations": { 3 | "activityBar.activeBackground": "#93e6fc", 4 | "activityBar.activeBorder": "#fa45d4", 5 | "activityBar.background": "#93e6fc", 6 | "activityBar.foreground": "#15202b", 7 | "activityBar.inactiveForeground": "#15202b99", 8 | "activityBarBadge.background": "#fa45d4", 9 | "activityBarBadge.foreground": "#15202b", 10 | "editorGroup.border": "#93e6fc", 11 | "panel.border": "#93e6fc", 12 | "sideBar.border": "#93e6fc", 13 | "statusBar.background": "#93e6fc", 14 | "statusBar.foreground": "#15202b", 15 | "statusBarItem.hoverBackground": "#61dbfb", 16 | "tab.activeBorder": "#93e6fc", 17 | "titleBar.activeBackground": "#93e6fc", 18 | "titleBar.activeForeground": "#15202b", 19 | "titleBar.inactiveBackground": "#93e6fc99", 20 | "titleBar.inactiveForeground": "#15202b99" 21 | }, 22 | "peacock.remoteColor": "#61dbfb" 23 | } -------------------------------------------------------------------------------- /next.js/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:14.15.4-alpine3.12 2 | 3 | RUN apk add --no-cache bash 4 | 5 | USER node 6 | 7 | WORKDIR /home/node/app -------------------------------------------------------------------------------- /next.js/README.md: -------------------------------------------------------------------------------- 1 | This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). 2 | 3 | ## Getting Started 4 | 5 | First, run the development server: 6 | 7 | ```bash 8 | npm run dev 9 | # or 10 | yarn dev 11 | ``` 12 | 13 | Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. 14 | 15 | You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file. 16 | 17 | [API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`. 18 | 19 | The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages. 20 | 21 | ## Learn More 22 | 23 | To learn more about Next.js, take a look at the following resources: 24 | 25 | - [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. 26 | - [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. 27 | 28 | You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! 29 | 30 | ## Deploy on Vercel 31 | 32 | The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. 33 | 34 | Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. 35 | -------------------------------------------------------------------------------- /next.js/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | app: 5 | build: . 6 | entrypoint: ./entrypoint.sh 7 | ports: 8 | - 3001:3000 9 | volumes: 10 | - .:/home/node/app 11 | extra_hosts: 12 | - "host.docker.internal:172.17.0.1" 13 | 14 | -------------------------------------------------------------------------------- /next.js/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | npm install 4 | 5 | npm run dev -------------------------------------------------------------------------------- /next.js/jwt.drawio: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /next.js/next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | 5 | // NOTE: This file should not be edited 6 | // see https://nextjs.org/docs/basic-features/typescript for more information. 7 | -------------------------------------------------------------------------------- /next.js/next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | module.exports = { 3 | reactStrictMode: true, 4 | } 5 | -------------------------------------------------------------------------------- /next.js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "live-nextjs-auth", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start", 9 | "lint": "next lint" 10 | }, 11 | "dependencies": { 12 | "@react-keycloak/ssr": "^3.3.0", 13 | "axios": "^0.21.4", 14 | "cookie": "^0.4.1", 15 | "js-cookie": "^3.0.1", 16 | "jsonwebtoken": "^8.5.1", 17 | "keycloak-js": "^15.0.2", 18 | "next": "11.1.2", 19 | "react": "17.0.2", 20 | "react-dom": "17.0.2", 21 | "swr": "^1.0.0" 22 | }, 23 | "devDependencies": { 24 | "@types/cookie": "^0.4.1", 25 | "@types/js-cookie": "^2.2.7", 26 | "@types/jsonwebtoken": "^8.5.5", 27 | "@types/react": "17.0.20", 28 | "eslint": "7.32.0", 29 | "eslint-config-next": "11.1.2", 30 | "typescript": "4.4.2" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /next.js/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codeedu/live-multi-tenancy-nest-next-keycloak/9c67254ae186dadfa851a0c0c9779792f418f5d5/next.js/public/favicon.ico -------------------------------------------------------------------------------- /next.js/public/silent-check-sso.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | -------------------------------------------------------------------------------- /next.js/public/vercel.svg: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /next.js/src/hof/withAuth.tsx: -------------------------------------------------------------------------------- 1 | import { getPayload, isTokenExpired } from "../util/auth"; 2 | import { parseCookies } from "../util/cookies"; 3 | 4 | export function withAuth(func: any) { 5 | return async (ctx: any) => { 6 | const cookies = parseCookies(ctx.req); 7 | 8 | if (!cookies.token || isTokenExpired(cookies.token)) { 9 | return { 10 | redirect: { 11 | permanent: false, 12 | destination: "/login", 13 | }, 14 | }; 15 | } 16 | 17 | const payload = getPayload(cookies.token); 18 | 19 | const result = await func(ctx, cookies, payload); 20 | if ("props" in result) { 21 | result.props = { 22 | payload, 23 | ...result.props, 24 | }; 25 | } 26 | 27 | return result; 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /next.js/src/hooks/useAuthHttp.ts: -------------------------------------------------------------------------------- 1 | import { http } from "./../util/http"; 2 | import useSWR from "swr"; 3 | import { useEffect } from "react"; 4 | import Router from "next/router"; 5 | 6 | const fetcher = (url: string) => http.get(url).then((res) => res.data); 7 | 8 | export function useAuthHttp(url: string) { 9 | const { data, error } = useSWR(url, fetcher); 10 | 11 | useEffect(() => { 12 | if (error?.response?.status === 401) { 13 | Router.push("/login"); 14 | } 15 | }, [error]); 16 | 17 | return { data, error }; 18 | } 19 | -------------------------------------------------------------------------------- /next.js/src/pages/_app.tsx: -------------------------------------------------------------------------------- 1 | import type { AppContext, AppProps } from "next/app"; 2 | import { SSRKeycloakProvider, SSRCookies } from "@react-keycloak/ssr"; 3 | import { KEYCLOAK_CONFIG } from "../util/auth"; 4 | import { parseCookies } from "../util/cookies"; 5 | 6 | function MyApp({ Component, pageProps, cookies }: AppProps & { cookies: any }) { 7 | return ( 8 | 19 | 20 | 21 | ); 22 | } 23 | 24 | MyApp.getInitialProps = async (appContext: AppContext) => { 25 | return { 26 | cookie: parseCookies(appContext.ctx.req), 27 | }; 28 | }; 29 | export default MyApp; 30 | 31 | //gateway para as paginas react 32 | -------------------------------------------------------------------------------- /next.js/src/pages/api/hello.ts: -------------------------------------------------------------------------------- 1 | // Next.js API route support: https://nextjs.org/docs/api-routes/introduction 2 | import type { NextApiRequest, NextApiResponse } from 'next' 3 | 4 | type Data = { 5 | name: string 6 | } 7 | 8 | export default function handler( 9 | req: NextApiRequest, 10 | res: NextApiResponse 11 | ) { 12 | res.status(200).json({ name: 'John Doe' }) 13 | } 14 | -------------------------------------------------------------------------------- /next.js/src/pages/index.tsx: -------------------------------------------------------------------------------- 1 | import { useKeycloak } from "@react-keycloak/ssr"; 2 | import type { NextPage } from "next"; 3 | import { useRouter } from "next/router"; 4 | 5 | const Home: NextPage = () => { 6 | const { initialized, keycloak } = useKeycloak(); 7 | 8 | const router = useRouter(); 9 | console.log(router); 10 | if ( 11 | typeof window !== "undefined" && 12 | initialized && 13 | !keycloak?.authenticated 14 | ) { 15 | router.replace("/login"); 16 | return null; 17 | } 18 | 19 | return keycloak?.authenticated ?
Hello World
: null; 20 | }; 21 | 22 | export default Home; 23 | -------------------------------------------------------------------------------- /next.js/src/pages/login.tsx: -------------------------------------------------------------------------------- 1 | import { useKeycloak } from "@react-keycloak/ssr"; 2 | import { KeycloakInstance } from "keycloak-js"; 3 | import { useEffect } from "react"; 4 | import Router from 'next/router'; 5 | 6 | const LoginPage = () => { 7 | const { initialized, keycloak } = useKeycloak(); 8 | 9 | const { login = () => {}, authenticated } = keycloak || {}; 10 | 11 | useEffect(() => { 12 | if (!initialized) { 13 | return; 14 | } 15 | if (!authenticated) { 16 | login(); 17 | } 18 | }, [login, authenticated, initialized]); 19 | 20 | useEffect(() => { 21 | if(!initialized){ 22 | return; 23 | } 24 | 25 | if(authenticated){ 26 | Router.replace('/private'); 27 | } 28 | }) 29 | 30 | return null; 31 | }; 32 | 33 | export default LoginPage; 34 | -------------------------------------------------------------------------------- /next.js/src/pages/pagina1.tsx: -------------------------------------------------------------------------------- 1 | import { GetServerSideProps } from "next"; 2 | 3 | const Pagina1Page = ({name}: {name: string}) => { 4 | return
Pagina1 - {name}
; 5 | }; 6 | 7 | export default Pagina1Page; 8 | 9 | export const getServerSideProps: GetServerSideProps = async (ctx) => { 10 | 11 | //banco de dados 12 | //api externa 13 | return { 14 | props: { 15 | name: 'Luiz Carlos' 16 | } 17 | } 18 | }; 19 | 20 | //Node.js 21 | //Create React App - Facebook - Client Side Render -------------------------------------------------------------------------------- /next.js/src/pages/private.tsx: -------------------------------------------------------------------------------- 1 | import { NextPage } from "next"; 2 | import { Token, validateAuth } from "../util/auth"; 3 | import { http } from "../util/http"; 4 | 5 | interface PrivatePageProps { 6 | name: string; 7 | payload: any; 8 | } 9 | 10 | const PrivatePage: NextPage = (props) => { 11 | console.log(props.payload); 12 | return
Pagina privada {props.name}
; 13 | }; 14 | 15 | export default PrivatePage; 16 | 17 | export const getServerSideProps = async (ctx: any) => { 18 | const auth = validateAuth(ctx.req); 19 | 20 | //console.log(ctx.req.headers.cookie); 21 | 22 | if (!auth) { 23 | return { 24 | redirect: { 25 | permanent: false, 26 | destination: "/login", 27 | }, 28 | }; 29 | } 30 | const token = (auth as Token).token; 31 | const { data } = await http.get("test-auth", { 32 | headers: { 33 | Authorization: `Bearer ${token}`, 34 | }, 35 | }); 36 | 37 | return { 38 | props: data, 39 | }; 40 | }; 41 | 42 | // export const getServerSideProps = withAuth( 43 | // async (ctx: any, cookies: any, payload: any) => { 44 | // console.log(cookies); 45 | // const { data } = await http.get("test-auth", { 46 | // headers: { 47 | // Authorization: `Bearer ${cookies.token}`, 48 | // }, 49 | // }); 50 | // return { 51 | // props: data, 52 | // }; 53 | // } 54 | // ); 55 | 56 | // export const getServerSideProps: GetServerSideProps = async (ctx) => { 57 | // const cookies = parseCookies(ctx.req); 58 | 59 | // if (!cookies.token || isTokenExpired(cookies.token)) { 60 | // return { 61 | // redirect: { 62 | // permanent: false, 63 | // destination: "/login", 64 | // }, 65 | // }; 66 | // } 67 | 68 | // //try { 69 | // const { data } = await http.get("test-auth", { 70 | // headers: { 71 | // Authorization: `Bearer ${cookies.token}`, 72 | // }, 73 | // }); 74 | // // } catch (e) { 75 | // // if ( 76 | // // axios.isAxiosError(e) && 77 | // // (e.response?.status === 401 || e.response?.status === 403) 78 | // // ) { 79 | // // return { 80 | // // redirect: { 81 | // // permanent: false, 82 | // // destination: "/login", 83 | // // }, 84 | // // }; 85 | // // } 86 | 87 | // // throw e; 88 | // // } 89 | 90 | // return { 91 | // props: data, 92 | // }; 93 | // }; 94 | //JWT - tempo de vida - 60s 95 | -------------------------------------------------------------------------------- /next.js/src/styles/LoginPage.module.css: -------------------------------------------------------------------------------- 1 | .formGroup { 2 | display: flex; 3 | flex-direction: column; 4 | } 5 | -------------------------------------------------------------------------------- /next.js/src/util/auth.ts: -------------------------------------------------------------------------------- 1 | import jwt, { JwtPayload } from "jsonwebtoken"; 2 | import { KeycloakProfile, KeycloakTokenParsed } from "keycloak-js"; 3 | import { parseCookies } from "./cookies"; 4 | 5 | export const KEYCLOAK_CONFIG = { 6 | realm: process.env.NEXT_PUBLIC_KEYCLOAK_REALM, 7 | clientId: process.env.NEXT_PUBLIC_KEYCLOAK_CLIENT_ID, 8 | url: process.env.NEXT_PUBLIC_KEYCLOAK_URL, 9 | }; 10 | 11 | export function isTokenExpired(token: string) { 12 | const payload = getPayload(token); 13 | 14 | const clockTimestamp = Math.floor(Date.now() / 1000); 15 | 16 | return clockTimestamp > payload.exp; 17 | } 18 | 19 | export function getPayload(token: string) { 20 | return JSON.parse( 21 | Buffer.from(token.split(".")[1], "base64").toString("utf8") 22 | ); 23 | } 24 | 25 | export type Payload = KeycloakTokenParsed & 26 | KeycloakProfile; 27 | 28 | export type Token = { token: string; payload: Payload }; 29 | 30 | type Request = { headers: { cookie?: any } }; 31 | 32 | export function validateAuth(req?: Request): Token | boolean { 33 | const cookies = parseCookies(req); 34 | if (!cookies.kcToken) { 35 | return false; 36 | } 37 | const token = Buffer.from(cookies.kcToken, "base64").toString("utf8"); 38 | const payloadOrFalse = verifyToken(token, process.env.JWT_SECRET as string); 39 | return payloadOrFalse 40 | ? ({ token, payload: payloadOrFalse } as any) 41 | : payloadOrFalse; 42 | } 43 | //verificação completa 44 | export function verifyToken(token: string, key: string): JwtPayload | false { 45 | try { 46 | return jwt.verify(token, key, { ignoreExpiration: false }) as JwtPayload; 47 | } catch (e) { 48 | console.error(e, token, key); 49 | return false; 50 | } 51 | } 52 | 53 | 54 | //header.payload.signature {} 55 | -------------------------------------------------------------------------------- /next.js/src/util/cookies.ts: -------------------------------------------------------------------------------- 1 | import cookie from "cookie"; 2 | import Cookies from "js-cookie"; 3 | 4 | export function parseCookies(req?: any) { 5 | if (!req || !req.headers) { 6 | return {}; 7 | } 8 | 9 | return cookie.parse(req.headers.cookie || ""); 10 | } 11 | 12 | export function setCookie( 13 | key: string, 14 | value: string | object, 15 | options?: Cookies.CookieAttributes 16 | ) { 17 | Cookies.set(key, value, { 18 | ...options, 19 | secure: process.env.NODE_ENV === "production" ? true : false, 20 | }); 21 | } 22 | 23 | export function getCookie(key: string){ 24 | return Cookies.get(key); 25 | } 26 | -------------------------------------------------------------------------------- /next.js/src/util/http.ts: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | import { getCookie } from "./cookies"; 3 | 4 | export const http = axios.create({ 5 | baseURL: "http://host.docker.internal:3000", 6 | }); 7 | 8 | http.interceptors.request.use((request) => { 9 | if (!process.browser) { 10 | return request; 11 | } 12 | 13 | const token = getCookie("token"); 14 | 15 | if (token) { 16 | request.headers["Authorization"] = `Bearer ${token}`; 17 | } 18 | 19 | return request; 20 | }); 21 | -------------------------------------------------------------------------------- /next.js/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": true, 8 | "forceConsistentCasingInFileNames": true, 9 | "noEmit": true, 10 | "esModuleInterop": true, 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "resolveJsonModule": true, 14 | "isolatedModules": true, 15 | "jsx": "preserve" 16 | }, 17 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], 18 | "exclude": ["node_modules"] 19 | } 20 | --------------------------------------------------------------------------------