2016-04-07 1 views
0

こんにちは私は、ユーザーが新しいアカウントを作成してログインできるEmberとFirebaseを使ってアプリを作っています。彼のアカウントと保護されたルートについての情報は、彼が許可されているときにのみ見ることができます。認証されていないユーザーには、ログインフォームを表示するインデックス( '/')と表示されるサインアップルート( '/ signup')へのリンクのみが表示され、新しいアカウントを作成できるようになります。ユーザの承認後にインデックス/インデックスルートのモデルフックを呼び出す方法は?

Router.map(function() { 
    this.route('signup'); 
    this.route('index', {path: '/'}, function() { 
    this.authenticatedRoute('index', {path: '/'}); 
    this.authenticatedRoute('events'); 
    this.authenticatedRoute('about'); 
    }); 
}); 

アプリ/テンプレート/ index.hbsは、ログインフォームが含まれており、ネストされたインデックスのルートユーザがログインがレンダリングされますが、それはモデルフックだときに呼び出されていない、それまで:マイアプリ/ router.jsルータは、次のようになりますリフレッシュされます。それを動作させるには?

APP /テンプレート/ index.hbs

{{#unless session.isAuthenticated}} 

    {{signin-form store=store session=session authorized="authorized"}} 

{{else}} 

    {{#link-to 'index.index' class="item"}}Home{{/link-to}} 
    {{#link-to 'index.events' class="item"}}Events{{/link-to}} 
    {{#link-to 'index.about' class="item"}}About{{/link-to}} 


    {{outlet}} 

{{/unless}} 

APP /ルート/で

import Ember from 'ember'; 

export default Ember.Route.extend({ 
    beforeModel() { 
    return this.get("session").fetch().catch(function() {}); 
    }, 
    actions: { 
    signOut() { 
     this.get('session').close(); 
     this.transitionTo('index'); 
    }, 
    accessDenied() { 
     this.transitionTo('index'); 
    }, 
    authorized() { 
     console.log('authorized'); 
     this.transitionTo('index'); 
    } 
    } 
}); 

APP /コンポーネント/サインイン-form.js

答えて

0
import Ember from 'ember'; 

export default Ember.Component.extend({ 
    didRender() { 
    this._super(...arguments); 
    this.$('form.ui.form').form(); 
    }, 

    signIn() { 
    let { userPassword, userEmail } 
     = this.getProperties('userPassword', 'userEmail'); 
    console.log('Logging with', userPassword, userEmail); 
    this.get("session").open("firebase", { 
     provider: 'password', 
     email: userEmail, 
     password: userPassword 
    }).then((data) => { 
     console.log(data); 
     this.sendAction('authorized'); 
    }); 
    }, 

    actions: { 
    submit() { 
     this.signIn(); 
    } 
    } 

}); 

をapplication.js app/routes/application.js変更しました

authorized() { 
    this.transitionTo('index'); 
} 

authorized() { 
    this.refresh(); 
} 

今では動作します。しかし、一般的に私はまだこの解決策に疑問を抱いています。あなたがそれをより良く/恵まれた方法で見たら、それについて聞いてうれしいです。

+0

ログイン用に別のルートを使用し、beforeModelフックを使用してこのルートにユーザーをリダイレクトすることをお勧めします。 'ember-simple-auth'がどのように機能するか見てみましょう。 – Lux

関連する問題