zackyang000 / node-odata

A library for easily create OData REST API, abide by OData protocol.
http://zackyang000.github.io/node-odata/en/
MIT License
365 stars 65 forks source link

Async Auth support #84

Open emathias opened 7 years ago

emathias commented 7 years ago

Hi,

As of now, the implementation of node-odata requires 'auth' to be synchronous, as it has to return true or false. (as described here: http://tossshinhwa.github.io/node-odata/en/#51-resource)

In realistic scenarios, checking auth may usually entail some async operation (checking DB, etc) and because of the async nature of node, a control flow as express middleware (using next() ) seems more appropriate.

What do you think ?

Best,

zackyang000 commented 7 years ago

Hi @emathias

There has another way to implement this.

You can add middleware to handle auth check, it support async function, and put the result into req, then auth hook just check this field.

Here is a example: middleware, auth hook.

But it can not solve some complex scene problems, such as data permissions check, I will try to let it become to a async function later.

Thank you.