Git Product home page Git Product logo

Comments (6)

thiagobustamante avatar thiagobustamante commented on July 29, 2024 2

Hi,

Typescript-rest works over expressjs. Express allows you to create middlewares to intercept your requests. Take a look at this and this to see how to create middlewares to express.

Check this for an example of using express middlewares with typescript-rest and this for authentication.

from typescript-rest.

ngraef avatar ngraef commented on July 29, 2024 1

The new @Preprocessor feature should solve this issue.

from typescript-rest.

creadicted avatar creadicted commented on July 29, 2024

Is authentication and authorization not just a route that you call that creates a response based on your model? Middleware you can just add like in express:
https://github.com/thiagobustamante/typescript-rest#registering-services

from typescript-rest.

nkimaina avatar nkimaina commented on July 29, 2024

Sorry I didn't state what I wanted to achieve clearly. I was looking for a way to do an interceptor (or transfer control to some chunk of code), before control is given to a certain route handler.
That way, you can do checks to determine if a route can be executed or not. I am coming from a hapijs background, and we could achieve this using hapijs plugins. In microsoft's web api, they are called 'filters'.

from typescript-rest.

nkimaina avatar nkimaina commented on July 29, 2024

I saw that someone asked a similar question. #23. I now see how to do it. I wish it was possible to do something like:
//import some auth filter that is singleton
import authFilter from './some-authentication-filter';

//inside a controller class
@get
@path('test')
@filter(authFilter)
async test( ) {
let result = await this.aPromiseMethod();
return result;
}

Looks elegant, doesn't it? Maybe this is supposed to be a feature request to implement such a decorator? I could do such a thing if you guided me.

from typescript-rest.

nkimaina avatar nkimaina commented on July 29, 2024

This is awesome! Thanks so much @ngraef

from typescript-rest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.