Comments (2)
You can use JWT for authentication in this boilerplate by change src/auth/authorizationChecker.ts files
In my case, I add "BearerTokenMiddleware.ts" in directory /src/api/middlewares/
using npm "@bukalapak/express-bearer-token "
this is my code
import * as express from 'express'
import bearertoken from '@bukalapak/express-bearer-token'
import { ExpressMiddlewareInterface, Middleware } from 'routing-controllers'
@Middleware({ type: 'before' })
export class BearerTokenMiddleware implements ExpressMiddlewareInterface {
use(
req: express.Request,
res: express.Response,
next: express.NextFunction
): any {
return bearertoken()(req, res, next)
}
}
and then you can get jwt in request.token
now you have to change some codes in authorizationChecker.ts
in my case
export const authorizationChecker = (): ((
action: Action,
roles: any[]
) => Promise<boolean> | boolean) => {
const userService = Container.get<UserService>(UserService)
const authService = Container.get<AuthService>(AuthService)
return async (action: Action, roles: string[]): Promise<boolean> => {
// token text is in action.request.token
const token = action.request.token
// pareseFromRequest -> logic that verify jwt by your own secret key
const { userInfo } = authService.parseFromRequest(token)
// if got some errors in token or in select user, have to response errors
// if you set request.user like this you can get currentUser by using "currentUser" in "routing-controllers"
action.request.user = await userService
.findOne({ where: { ...conditions } })
return true
}
}
Hope that my comment can help you anyway
from express-typescript-boilerplate.
+1
from express-typescript-boilerplate.
Related Issues (20)
- Docker build fails HOT 2
- Seeding out of date
- File upload using multer integration
- Errors when installing on Ubuntu 18 LTS HOT 2
- How can i integrate JWT Authentication in this boiler plate HOT 1
- Error when installing (bcrypt) HOT 1
- Error connecting to PostgreSQL with SSL
- error while yarn run setup command HOT 5
- Integrate with Relative Path
- How to set Elastic search Loader?
- About public route without authentication
- Update version of bcrypt and sqlite3 to 5.0.1 and 5.0.0 respectively HOT 8
- How to use winston?
- Why use CommonJS?
- 'yarn start serve' does not start the server HOT 1
- Bcrypt installation errors on M1 Mac HOT 4
- docker not started nps not found
- Cannot create migrations
- Witch branch Should I use ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-typescript-boilerplate.