Skip to content

Commit 5fa085b

Browse files
nesjts-app-jwt
1 parent 3c33cc8 commit 5fa085b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+20109
-0
lines changed

.dockerignore

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
# dependencies
3+
/node_modules
4+
/.pnp
5+
.pnp.js
6+
7+
# testing
8+
/coverage
9+
10+
# production
11+
/build
12+
13+
# misc
14+
.DS_Store
15+
.env.local
16+
.env.development.local
17+
.env.test.local
18+
.env.production.local
19+
20+
npm-debug.log*
21+
yarn-debug.log*
22+
yarn-error.log*

.env.development

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
NODE_ENV=development
2+
MONGODB_URI=mongodb://localhost:27017/test
3+
SERVER_URL=http://localhost:3000/
4+
PORT=3000
5+
JWT_KEY='MXvTnOhWYMYgYiFnBFRfX4Fnd4ZkXLK8qYU'
6+
IS_COOKIE_AUTH=false

.env.production

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
NODE_ENV=production
2+
MONGODB_URI=mongodb://host.docker.internal:27017/test
3+
SERVER_URL=https://production.yourapi.com/
4+
PORT=3000
5+
JWT_KEY='MXvTnOhWYMYgYiFnBFRfX4Fnd4ZkXLK8qYU'
6+
IS_COOKIE_AUTH=false

.env.staging

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
NODE_ENV=staging
2+
MONGODB_URI=mongodb://<staging_db_url>:27017/test_staging
3+
SERVER_URL=https://staging.yourapi.com/
4+
PORT=3000
5+
JWT_KEY='MXvTnOhWYMYgYiFnBFRfX4Fnd4ZkXLK8qYU'
6+
IS_COOKIE_AUTH=false

.env.test

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
NODE_ENV=test
2+
MONGODB_URI=mongodb://localhost:27017/test
3+
SERVER_URL=http://localhost:3000/
4+
PORT=3000
5+
JWT_KEY='MXvTnOhWYMYgYiFnBFRfX4Fnd4ZkXLK8qYU'
6+
IS_COOKIE_AUTH=false

.eslintrc.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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/eslint-recommended',
10+
'plugin:@typescript-eslint/recommended',
11+
'prettier',
12+
],
13+
root: true,
14+
env: {
15+
node: true,
16+
jest: true,
17+
},
18+
rules: {
19+
'@typescript-eslint/interface-name-prefix': 'off',
20+
'@typescript-eslint/explicit-function-return-type': 'off',
21+
'@typescript-eslint/no-explicit-any': 'off',
22+
},
23+
};

.gitignore

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# Snowpack dependency directory (https://snowpack.dev/)
46+
web_modules/
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Optional stylelint cache
58+
.stylelintcache
59+
60+
# Microbundle cache
61+
.rpt2_cache/
62+
.rts2_cache_cjs/
63+
.rts2_cache_es/
64+
.rts2_cache_umd/
65+
66+
# Optional REPL history
67+
.node_repl_history
68+
69+
# Output of 'npm pack'
70+
*.tgz
71+
72+
# Yarn Integrity file
73+
.yarn-integrity
74+
75+
# dotenv environment variable files
76+
.env
77+
.env.development.local
78+
.env.test.local
79+
.env.production.local
80+
.env.local
81+
82+
# parcel-bundler cache (https://parceljs.org/)
83+
.cache
84+
.parcel-cache
85+
86+
# Next.js build output
87+
.next
88+
out
89+
90+
# Nuxt.js build / generate output
91+
.nuxt
92+
dist
93+
94+
# Gatsby files
95+
.cache/
96+
# Comment in the public line in if your project uses Gatsby and not Next.js
97+
# https://nextjs.org/blog/next-9-1#public-directory-support
98+
# public
99+
100+
# vuepress build output
101+
.vuepress/dist
102+
103+
# vuepress v2.x temp and cache directory
104+
.temp
105+
.cache
106+
107+
# Serverless directories
108+
.serverless/
109+
110+
# FuseBox cache
111+
.fusebox/
112+
113+
# DynamoDB Local files
114+
.dynamodb/
115+
116+
# TernJS port file
117+
.tern-port
118+
119+
# Stores VSCode versions used for testing VSCode extensions
120+
.vscode-test
121+
122+
# yarn v2
123+
.yarn/cache
124+
.yarn/unplugged
125+
.yarn/build-state.yml
126+
.yarn/install-state.gz
127+
.pnp.*

.husky/pre-commit

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npm test
5+
npm test

Dockerfile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Base image
2+
FROM node:18
3+
4+
# Create app directory
5+
WORKDIR /usr/src/app
6+
7+
# A wildcard is used to ensure both package.json AND package-lock.json are copied
8+
COPY package*.json ./
9+
10+
# Install app dependencies
11+
RUN npm install
12+
13+
# Bundle app source
14+
COPY . .
15+
16+
# Copy the .env and .env.development files
17+
COPY .env.development ./
18+
COPY .env.production ./
19+
20+
# Creates a "dist" folder with the production build
21+
RUN npm run build
22+
23+
# Expose the port on which the app will run
24+
EXPOSE 3000
25+
26+
# Start the server using the production build
27+
CMD ["npm", "run", "start:prod"]

README.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# NestJS Authentication JwtService
2+
3+
4+
![Prettier](https://img.shields.io/badge/Code%20style-prettier-informational?logo=prettier&logoColor=white)
5+
[![GPL v3 License](https://img.shields.io/badge/License-GPLv3-green.svg)](./LICENSE)
6+
[![HitCount](https://hits.dwyl.com/anilahir/nestjs-authentication-and-authorization.svg)](https://hits.dwyl.com/anilahir/nestjs-authentication-and-authorization)
7+
8+
## Description
9+
10+
NestJS Authentication with JwtService using Bcrypt @nestjs/jwt
11+
12+
## Features
13+
14+
1. Register
15+
2. Login
16+
3. Unit test
17+
18+
## Technologies stack:
19+
20+
- Typescript, nestjs, JwtService @nestjs/jwt
21+
- Bcrypt
22+
- mongoose
23+
24+
## Setup
25+
26+
### 1. Install the required dependencies
27+
28+
```bash
29+
$ npm install
30+
```
31+
32+
### 2. Rename the .env.example filename to .env and set your local variables
33+
34+
```bash
35+
$ mv .env.example .env
36+
```
37+
38+
### 3. Start the application
39+
40+
```bash
41+
# development
42+
$ npm run start
43+
44+
# watch mode
45+
$ npm run start:dev
46+
47+
# production mode
48+
$ npm run start:prod
49+
```
50+
51+
### Swagger documentation for nestjs-mongoose-jwt
52+
53+
### Running
54+
55+
```bash
56+
Once the application is running you can visit [http://localhost:3000/api](http://localhost:3000/api) to see the Swagger interface.
57+
```
58+
59+
## Author
60+
61+
👤 **Vinod**
62+
63+
- Github: [@vinodnextcoder](https://github.com/vinodnextcoder)
64+
65+
## Show your support
66+
67+
Give a ⭐️ if this project helped you!
68+
69+
## License
70+
71+
Release under the terms of [MIT](./LICENSE)

docker-compose.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: "3"
2+
3+
services:
4+
mongodb:
5+
image: mongo:latest
6+
environment:
7+
- MONGODB_DATABASE="test"
8+
ports:
9+
- 27017:27017

0 commit comments

Comments
 (0)