Skip to content

Instantly share code, notes, and snippets.

@acidsound
Created June 24, 2014 06:51
Show Gist options
  • Save acidsound/bfaf77dc8e1831571def to your computer and use it in GitHub Desktop.
Save acidsound/bfaf77dc8e1831571def to your computer and use it in GitHub Desktop.
accounts-password + iron-router 를 이용한 로그인+권한 구현
# 계정 생성
# Accounts.createUser({username:'kaka', password:'gogo'});
# Accounts.createUser({username:'admin', password:'admin', profile: {role: 'ADMIN'}});
Router.map ->
@route 'home', path: '/'
@route 'about'
@route 'admin'
@route 'noAuth'
# log in 실행 순서
# 1. user - undefined , loggingIn() - true
# 2. user - 유저정보 들어옴, loggingIn() - true
# 3. user - 유저정보 들어옴, loggingIn() - false : login 완료
Router.onBeforeAction (pause)->
user = Meteor.user()
console.log user, Meteor.loggingIn()
unless Meteor.loggingIn()
unless user and user.profile and user.profile.role is 'ADMIN'
Router.go 'noAuth'
else
# pause 하지 않으면 권한이 없는 사용자일 때 admin이 노출 됨
# loggingIn 하는 동안 render를 loggingIn으로 한다.
@render 'loggingIn'
pause()
,
only: ['admin']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment