totaljs / framework

Node.js framework
http://www.totaljs.com
Other
4.36k stars 450 forks source link

framework.onAuthorize is called at any request #568

Closed luoage closed 7 years ago

luoage commented 7 years ago

I have a simple authorization, so I rewrite F.onAuthorize

F.onAuthorize = function() {....};

And add flag to parameter.

F.route('/user/info', index, ['authorize', 'get']);

But when I open my index page that the page has no authorize flag, F.onAuthorize is called.

So, is that right ? I just want it called when the flags has authorize, how to make it possible ?

petersirka commented 7 years ago

Yes, it needs to be called each request because you need to know which user is logged in each route's action. Total.js supports these flags:

For understanding: Imagine we have an eshop application which have pages for all users and logged users. Homepage has to be rendered for all users (logged and unlogged together). But if some user is logged, you need to show his name in e.g. layout --> so for this case is needed to execute F.onAuthorize too. Current solution will work because F.onAuthorize is executed for all (controlller's) routes.

Solution for you:

Do you understand?

luoage commented 7 years ago

Oh, great thx !