2016-05-02 20 views
0

をユーザにログインしますユーザーアプリが起動時に - 。は、どのように私は私のfooter.htmlにサインインテンプレートを用意しました私は<code>accounts-password</code>と<code>useraccounts:unstyled</code></p> <p>を追加しました流星

import { Accounts } from 'meteor/accounts-base' 

if (!Acounts.findUserByEmail('[email protected]')) { 
    Accounts.createUser({ 
    username: 'Aidan', 
    email: '[email protected]', 
    password: 'securePassword' 
    }); 
} 

それは私が実際に私のユーザーをログに記録する方法を考え出すことができないことを、私は単純にフォームにパスワードとメールアドレスを入力しようとしただけです。それは動作しません(フォームエラーは「ログイン禁止」と表示されます)。

私は(私のアカウント作成コードと同じファイルに)次の行を追加しようとした -

accountsServer.validateLoginAttempt(()=>{return true;}); 

当然のことながら何もしません。私は、イベントが発火していることがわかります

Template.footer.events({ 
    'submit form'(event) { 
    console.log('submitted'); 
    const email = document.getElementById('at-field-email').value; 
    const password = document.getElementById('at-field-password').value; 
    Meteor.loginWithPassword(email, password); 
    }, 
}); 

が、私は、コンソールでMeteor.user()をしようとしたとき、私はまだnullを取得する - 私は私のfooter.jsファイルに提出するイベントを追加しようとした

答えて

-1

あなたは、{{> loginButtons}}を使用して機能を取得し、その機能には{{#if現在ユーザー}}を使用できます。

0

if (!Acounts.findUserByEmail('[email protected]'))(これはAccountsだったはずです)にタイプミスがあります。ユーザーは作成されていません。

単一のハードコーディングされたユーザーで超シンプルな機能ログイン取得するには - アカウントとパスワードのパッケージを追加します

をし、UI、ユーザーがパッケージを占めています。

> meteor add accounts-password 
> meteor add useraccouts:unstyled 

account-passwordパッケージは実際のログインを処理します。ユーザーアカウント:非構造化パッケージは、アカウント管理用のテンプレートセットを提供します。

次に、ログインフォームをテンプレートに追加します。

<template name="templateWithLogin"> 
    {{> atForm state="signIn"}} 
</template> 

最後に、ユーザーを作成します(例:/server/main.js)。

import { Accounts } from 'meteor/accounts-base'; 

if (!Accounts.findUserByEmail('[email protected]')) { 
    Accounts.createUser({ 
    username: 'User', 
    email: '[email protected]', 
    password: 'securePassword' 
    }); 
} 

これは、機能的なログインフォームを取得するために必要なすべてのものにする必要があります。追加の機能を作成するためのオンラインチュートリアルが多数あります。主な文書はhereです。

関連する問題

 関連する問題