こんにちは私は、ユーザーが新しいアカウントを作成してログインできる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
ログイン用に別のルートを使用し、beforeModelフックを使用してこのルートにユーザーをリダイレクトすることをお勧めします。 'ember-simple-auth'がどのように機能するか見てみましょう。 – Lux