我的routes.coffee
文件中包含以下代码,Router.onBeforeAction(...
函数似乎忽略了except
选项,并不断重定向到“登录”模板。这是为什么?
enforceLogin = ->
if Meteor.userId() is undefined or Meteor.userId() is null
isLoggedIn = false
Router.go '/sign-in'
else
isLoggedIn = true
return isLoggedIn
isCharacterNamed = ->
userCharacter = Characters.findOne ownedBy: Meteor.userId()
userCharacter.name is not undefined
checkCharacterNamed = (context) ->
if !isCharacterNamed()
Router.go 'create-character'
userCharactersSubscription = -> Meteor.subscribe 'userCharacters'
nonGameRoutes = ['sign-in', 'sign-up', 'sign-out', 'blog']
Router.map ->
@route 'home', path: '/'
@route 'adventures'
@route 'create-character', onBeforeAction: ->
enforceLogin()
if @ready()
if isCharacterNamed() then Router.go 'home'
@route 'blog'
@route 'admin/blog'
@route 'loading'
@route 'sign-in'
@route 'sign-up'
@route 'sign-out'
Router.onBeforeAction('loading')
Router.onBeforeAction enforceLogin, { except: nonGameRoutes }
Router.waitOn(userCharactersSubscription)
Router.onAfterAction ->
if @ready()
checkCharacterNamed()
@render()
else
@render('loading')
,
{ except: _.union(nonGameRoutes, ['create-character']) }
答案 0 :(得分:1)
尝试`Router.onBeforeAction enforceLogin,但不包括:nonGameRoutes