{"action":"created","issue":{"url":"https://api.github.com/repos/meteorhacks/flow-router/issues/66","labels_url":"https://api.github.com/repos/meteorhacks/flow-router/issues/66/labels{/name}","comments_url":"https://api.github.com/repos/meteorhacks/flow-router/issues/66/comments","events_url":"https://api.github.com/repos/meteorhacks/flow-router/issues/66/events","html_url":"https://github.com/meteorhacks/flow-router/issues/66","id":66216503,"number":66,"title":"Authentication middleware","user":{"login":"wI2L","id":6519569,"avatar_url":"https://avatars.githubusercontent.com/u/6519569?v=3","gravatar_id":"","url":"https://api.github.com/users/wI2L","html_url":"https://github.com/wI2L","followers_url":"https://api.github.com/users/wI2L/followers","following_url":"https://api.github.com/users/wI2L/following{/other_user}","gists_url":"https://api.github.com/users/wI2L/gists{/gist_id}","starred_url":"https://api.github.com/users/wI2L/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wI2L/subscriptions","organizations_url":"https://api.github.com/users/wI2L/orgs","repos_url":"https://api.github.com/users/wI2L/repos","events_url":"https://api.github.com/users/wI2L/events{/privacy}","received_events_url":"https://api.github.com/users/wI2L/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-04-03T19:43:21Z","updated_at":"2015-04-06T17:08:18Z","closed_at":"2015-04-06T17:08:18Z","body":"Hello arunoda,\r\n\r\nContinuing to try to port my IronRouter code to FlowRouter, i am facing a problem with middlewares.\r\nWith IronRouter, to ensure that a user was logged-in, i was using this code:\r\n\r\n```\r\n\r\nIron.Router.plugins.auth = function (router, options) {\r\n    router.onBeforeAction(function () {\r\n        if (!Meteor.user() && !Meteor.loggingIn()) {\r\n            if (Router.current() && Router.current().route)\r\n                Session.set('returnTo', Router.current().route.getName());\r\n            Router.go(options.authRoute);\r\n        }\r\n        this.next();\r\n    }, {\r\n        except: [\r\n            'signin',\r\n            'signup',\r\n            'lostPassword',\r\n            'resetPassword',\r\n            'verifyEmail'\r\n        ]\r\n    });\r\n};\r\n```\r\n\r\nNow, to switch to FlowRouter, i rewrited my code like this:\r\n\r\n```\r\nvar exceptions = [\r\n    '/signin',\r\n    '/signup',\r\n    '/lost-password',\r\n    '/reset-password',\r\n    '/verify-email'\r\n];\r\n\r\nFlowRouter.middleware(function (path, next) {\r\n    console.log(path);\r\n    if (!_.contains(exceptions, path)) {\r\n        if (!Meteor.userId()) {\r\n            Session.set('returnTo', path);\r\n            next('/signin');\r\n        }\r\n    }\r\n    next();\r\n});\r\n```\r\n\r\nThe main problem, if for routes `reset-password` and `verify-email`. Thoses routes accept a parameter `token`, and the this is the problem. I can't predict this token, ans so, i can't compare with the routes in the `exceptions` array.\r\n\r\nOf course, i could've split the `path` to keep only the first part of the route, but it will complexify the code.\r\n\r\nThis should be easy with named routes to handle this issue. Another way would be to provide `path` and `params` to middlewared callbacks separately.\r\n\r\nWhat do you think ?\r\n\r\nBest regards,\r\n\r\nWilliam"},"comment":{"url":"https://api.github.com/repos/meteorhacks/flow-router/issues/comments/90158722","html_url":"https://github.com/meteorhacks/flow-router/issues/66#issuecomment-90158722","issue_url":"https://api.github.com/repos/meteorhacks/flow-router/issues/66","id":90158722,"user":{"login":"arunoda","id":50838,"avatar_url":"https://avatars.githubusercontent.com/u/50838?v=3","gravatar_id":"","url":"https://api.github.com/users/arunoda","html_url":"https://github.com/arunoda","followers_url":"https://api.github.com/users/arunoda/followers","following_url":"https://api.github.com/users/arunoda/following{/other_user}","gists_url":"https://api.github.com/users/arunoda/gists{/gist_id}","starred_url":"https://api.github.com/users/arunoda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arunoda/subscriptions","organizations_url":"https://api.github.com/users/arunoda/orgs","repos_url":"https://api.github.com/users/arunoda/repos","events_url":"https://api.github.com/users/arunoda/events{/privacy}","received_events_url":"https://api.github.com/users/arunoda/received_events","type":"User","site_admin":false},"created_at":"2015-04-06T17:08:18Z","updated_at":"2015-04-06T17:08:18Z","body":"Hope we can close this. #59 has links to some answers."}}