2017-12-01 7 views
0

ユーザーの電子メールアドレスを更新するためのサーバー上のメソッドがあります。私はこれは、ユーザーが1つの電子メールアドレスを持っている間だけ動作しますが、これは今でもOKです知っている。MeteorのセキュリティのためにMeteor.userId()を使用していますか?

Meteor.methods({ 
    'user.updateEmail'({ email, userId }) { 
    Meteor.users.update(
     { _id: userId }, 
     { 
     $set: { 
      'emails.0.address': email, 
      'emails.0.verified': false, 
     }, 
     }, 
    ); 
    }, 
}); 

イムリアクトコンポーネントにフォームからこのメソッドを呼び出す:

const formSubmit = e => { 
    e.preventDefault(); 
    const email = e.target.email.value; 
    const userId = Meteor.userId(); 
    Meteor.call('user.updateEmail', { email, userId }, err => { 
     if (err) { 
     alert(err); 
     } 
    }); 
    }; 

これは安全ではないですか?私はクライアントからuserIdを渡しているのでおそらくそれは変更される可能性がありますか?

答えて

0

あなたは正しいです。方法でMeteor.userId()を使用してユーザーのIDを受け取る必要があります。ユーザーはこれを変更することはできません。

0

クライアントからユーザーIDを渡すのは面倒ではありません。 - Get the current user record, or null if no user is logged in. A reactive data source Meteor.userId() - Get the current user id, or null if no user is logged in. A reactive data source this.userId - Access inside the publish function. The id of the logged-in user, or null if no user is logged inThe id of the user that made this method call, or null if no user was logged in

Meteor.user():あなたはMeteor.userId()

詳しい情報を使用して、サーバー自体からユーザーIDを取得することができます。

関連する問題