LOGIN과
권한

이번에도

Live Coding!

목표

  1. route 별로 필터를 만든다.
  2. 유저에 따라 특정 route의 접속을 제한한다.
  3. login 유저를 구분한다.

생성

meteor create loginWithAuth
cd loginWithAuth
rm loginWithAuth.*

iron-router 추가

meteor add  iron-router

Home/About 추가

<template name="home">
  <h1>Hello buddies!</h1>
</template>

<template name="about">
  <h1>about</h1>
</template>

Route

Router.map(function() {
  this.route('home', {
    path: '/'
  });
  this.route('about');
});

Route 추가

admin

noAuth

loggingIn

Router.onBeforeAction


user login 여부 확인

logginIn

login중인지 확인

log in 실행 순서


  1. user - undefined , loggingIn() - true
  2. user - 유저정보 들어옴, loggingIn() - true
  3. user - 유저정보 들어옴, loggingIn() - false : login 완료

Role

권한이 있는지?

Putting It All Together


Router.map(function() {
  this.route('home', { path: '/' });
  this.route('about');
  this.route('admin');
  this.route('noAuth');
});
Router.onBeforeAction(function(pause) {
  var user;
  user = Meteor.user();
  if (!Meteor.loggingIn()) {
    if (!(user && user.profile && user.profile.role === 'ADMIN')) {
      Router.go('noAuth');
    }
  } else {
    this.render('loggingIn');
    pause();
  }
}, {
  only: ['admin']
});


meteor-login

By Lee Jaeho

meteor-login

  • 1,204