Created
February 3, 2013 22:53
-
-
Save alanning/4704096 to your computer and use it in GitHub Desktop.
meteor-mini-pages - Before callback hack to transparently render a different template than originally defined.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var beforeFilters = { | |
authenticate: function (context, page) { | |
var user | |
if (Meteor.loggingIn()) { | |
console.log('authenticate: loading') | |
//context.redirect( Meteor.loadingPath() ) | |
if (!page.origTemplate) { | |
page.origTemplate = page.templateName | |
} | |
page.templateName = 'loading' | |
context.loading = true | |
context.handled = true | |
return | |
} else { | |
delete context.loading | |
user = Meteor.user() | |
if (!user) { | |
console.log('authenticate: login') | |
//context.redirect( Meteor.loginPath() ) | |
if (!page.origTemplate) { | |
page.origTemplate = page.templateName | |
} | |
page.templateName = 'login' | |
context.loggingIn = true | |
context.handled = true | |
return | |
} | |
delete context.loggingIn | |
if (!emailVerified(user)) { | |
console.log('authenticate: awaitingVerification') | |
//context.redirect( Meteor.awaitingVerificationPath() ) | |
if (!page.origTemplate) { | |
page.origTemplate = page.templateName | |
} | |
page.templateName = 'awaitingVerification' | |
context.handled = true | |
return | |
} | |
} | |
console.log('authenticate: passed') | |
if (page.origTemplate) { | |
// restore original template | |
console.log('authenticate: restoring original template - ' + page.origTemplate) | |
page.templateName = page.origTemplate | |
delete page.origTemplate | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cc @pkaushik
Thanks for showing me this use case @alanning. In the next release I think I need to address this because the authorize() case falls apart a little with the current design. I'm thinking it would be nice to have something like:
I'd also like to make it easier to specify global before filters so you don't have to type it for every route. Any ideas?