簡體   English   中英

如何檢查當前用戶電子郵件是否已在客戶端js文件中驗證

[英]How to check if current user email has been verified in client js file

此Meteor客戶端javascript需要確定當前用戶電子郵件是否已通過驗證。
有沒有比先檢查emails屬性是否存在然后再檢查數組中的第一項以查看其屬性是否設置為true的簡便方法? 謝謝

const val = Meteor.users.findOne({_id: userId}).emails[0].verified;

我知道下面的代碼可以在html文件中工作,但我需要js文件中的值。

{{#unless currentUser.emails.[0].verified}}

為此,我已經定義了一個全局幫助器:

// return true/false depending on whether the referenced user's email has been verified
Template.registerHelper('isVerified',function(){ 
  return this.emails && this.emails[0].verified; // we're in a user context
  else return Meteor.user().emails && Meteor.user().emails[0].verified; // look at the current user
});

然后從大火:

{{#if isVerified}}...{{/if}}

或從js:

if ( UI._globalHelpers.isVerified() ) ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM