You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Replace session authentication by JWT authentication
* Remove wrong information in README
* Remove resolutions in package lock
* Upgraded packages minor version
* Upgrade package bcrypt
* Remove caret in package json
Copy file name to clipboardExpand all lines: README.md
+15-39Lines changed: 15 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@
19
19
</p>
20
20
21
21
<palign="center">
22
-
<b>A modern boilerplate for building scalable and maintainable REST APIs with authentication, written in TypeScript. It features Docker, Express, TypeORM, Passport, and integrates Clean Architecture principles with Dependency Injection powered by Inversify.</b></br>
22
+
<b>A modern boilerplate for building scalable and maintainable REST APIs with authentication, written in TypeScript. It features Docker, Express, TypeORM, jsonwebtoken for authentication by JWT, and integrates Clean Architecture principles with Dependency Injection powered by Inversify.</b></br>
23
23
<sub>Made with ❤️ by <ahref="https://github.com/alexleboucher">Alex Le Boucher</a> and <ahref="https://github.com/alexleboucher/docker-express-postgres-boilerplate/graphs/contributors">contributors</a></sub>
24
24
</p>
25
25
@@ -35,7 +35,7 @@ It integrates common features such as:
35
35
36
36
- Docker containerization
37
37
- Database connection (PostgreSQL with TypeORM)
38
-
- Authentication (using Passport)
38
+
- Authentication (using jsonwebtoken)
39
39
- Centralized error handling
40
40
- Clean Architecture principles for better separation of concerns
41
41
- Dependency Injection powered by Inversify for modular and testable code
@@ -54,8 +54,7 @@ Packages are frequently upgraded. You can easily see the packages version status
54
54
## Features
55
55
56
56
-**Docker containerization** to easily run your code anywhere and avoid installing tools like PostgreSQL on your computer.
57
-
-**Authentication** with [Passport](https://www.passportjs.org/).
58
-
-**Authentication session** thanks to [express-session](https://github.com/expressjs/session) and [connect-pg-simple](https://github.com/voxpelli/node-connect-pg-simple).
57
+
-**Authentication by JWT** with [jsonwebtoken](https://github.com/auth0/node-jsonwebtoken).
59
58
-**Simplified Database Query** managed by [TypeORM](https://github.com/typeorm/typeorm).
60
59
-**Object-oriented database model** with [TypeORM](https://github.com/typeorm/typeorm) entities.
61
60
-**Integrated Testing Tools** with [Jest](https://jestjs.io/fr/docs/getting-started).
@@ -211,7 +210,6 @@ The project contains Github templates and workflows. If you don't want to keep t
211
210
| GET |`/health`| Retures the server health status | None. |
212
211
| POST |`/users`| Creates a new user. |`username` (min. 5 chars), `email` (valid), `password` (min. 8 chars). |
213
212
| POST |`/auth/login`| Logs in a user. |`email` and `password`. |
214
-
| POST |`/auth/logout`| Logs out the currently authenticated user. | None. |
215
213
| GET |`/auth/authenticated`| Returns the user authentication status | None. |
216
214
217
215
---
@@ -237,7 +235,7 @@ The project contains Github templates and workflows. If you don't want to keep t
237
235
|**src/domain/services/**| Interfaces for domain-level services (e.g., authentication, encryption). |
238
236
|**src/domain/use-cases/**| Use cases implementing business logic. |
239
237
|**src/infra/**| Infrastructure layer providing implementations for core and domain abstractions. |
240
-
|**src/infra/auth/**| Authentication implementations using Passport.js and session management. |
@@ -284,16 +277,7 @@ The project contains Github templates and workflows. If you don't want to keep t
284
277
285
278
## Authentication
286
279
287
-
This boilerplate uses `Passport.js` to handle authentication. `Passport.js` is a powerful, flexible, and modular middleware that allows you to implement various authentication strategies, including social logins (e.g., Google, Facebook, GitHub, etc.).
288
-
289
-
### Configuration
290
-
291
-
The configuration for `Passport` is located in `src/infra/auth/authenticator/passport-authenticator.ts`. This class centralizes the setup of strategies and the implementation of required methods like `serializeUser` and `deserializeUser`.
292
-
293
-
-**`serializeUser`**: Defines what data should be stored in the session. By default, it stores the user ID.
294
-
-**`deserializeUser`**: Fetches user information based on the session data and assigns it to `req.user`. This makes the authenticated user readily accessible via `req.user` without requiring additional calls.
295
-
296
-
You can find detailed documentation on `Passport.js`[here](https://www.passportjs.org/).
280
+
This boilerplate uses JSON Web Tokens to handle authentication with `jsonwebtoken`.
297
281
298
282
### Route Protection
299
283
@@ -303,22 +287,14 @@ To ensure route security and verify the user's authentication status, this boile
303
287
This middleware ensures the user is authenticated before allowing access to the route. It integrates seamlessly with the controllers, as shown in the example below:
2. The workflow `main-tests` is triggered when code is merged or pushed on main. It runs the tests and sends the coverage to [Codecov](https://about.codecov.io/). It has coverage for the main branch. If you don't want to keep it, you can delete the file `main-tests.yml` in the folder `workflows`.
552
528
553
-
If you want to keep the tests on pull request but don't want to use Codecov, you can delete `main-tests` and only delete the last step `Upload coverage to Codecov` in `pull-request.yml`. You can also delete `codecov.yml`.<br>
529
+
If you want to keep the tests on pull request but don't want to use Codecov, you can delete `main-tests` and only delete the last step `Upload coverage to Codecov` in `pull-request.yml`.<br>
554
530
But if you want to use CodeCov, the only thing you need to do is set your `CODECOV_TOKEN` in your github secrets.
555
531
556
532
3. The workflow `main-build` is triggered when something is merged or pulled on main. It builds the project and its primary goal is to check if main is building. If you don't want to keep it, you can delete the file `main-build.yml` in the folder `workflows`.
@@ -573,7 +549,7 @@ You can see the upcoming or in progress features [here](https://github.com/users
|[Express](https://expressjs.com/)| Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications. |
575
551
|[TypeORM](http://typeorm.io/#/)| TypeORM is highly influenced by other ORMs, such as Hibernate, Doctrine and Entity Framework. |
576
-
|[Passport](https://www.passportjs.org/)|Passport is authentication middleware for Node.js. Extremely flexible and modular, Passport can be unobtrusively dropped in to any Express-based web application. |
552
+
|[jsonwebtoken](https://github.com/auth0/node-jsonwebtoken)|An implementation of JSON Web Tokens for Node.js that helps you securely transmit information between parties as a JSON object. |
577
553
|[Docker](https://www.docker.com/)| Docker is a platform designed to help developers build, share, and run modern applications. We handle the tedious setup, so you can focus on the code. |
578
554
|[PostgreSQL](https://www.postgresql.org/)| PostgreSQL is a powerful, open source object-relational database system with over 35 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance. |
579
555
|[TypeScript](https://www.typescriptlang.org/)| TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale. |
0 commit comments