簡體   English   中英

如何驗證用戶是否已通過身份驗證並存在於 firebase 中,在 nodejs 中對 rest-api 進行讀/寫操作時,UI 位於 flutter 中?

[英]How to verify a user is authenticated and present in firebase, when doing read/write operations on the rest-api, in nodejs, UI is in flutter?

I have built a rest-api using Nodejs and mongodb for the flutter app, works completely fine and i am authenticating user using firebase phone authentication and I have some complex work, cannot be handled by the firebase, so setup a restapi for the work,因此,當用戶點擊 api 時,我想確保用戶在場並由 firebase 進行身份驗證,然后再從數據庫讀取和寫入,在服務器(api)端,用節點 js 編寫 如何實現這一點,有什么想法嗎?

PS:我對想法持開放態度,並提前感謝您的幫助:)

如果這樣做或有問題有任何問題,請建議編輯

只需使用 FirebaseAuth 的currentUser方法來驗證用戶是否已登錄

FirebaseUser user = await FirebaseAuth.instance.currentUser();
if(user!=null){
  // do your thing
}

編輯如果您想在您的服務器上驗證用戶,請在您的 Nodejs 服務器中使用 Firebase Admin SDK。 您必須傳遞一些標識符,例如 UID、email 或電話號碼; 以適用者為准。

admin.auth().getUser(uid)
  .then(function(userRecord) {
    // See the UserRecord reference doc for the contents of userRecord.
    console.log('Successfully fetched user data:', userRecord.toJSON());
  })
  .catch(function(error) {
    console.log('Error fetching user data:', error);
  });

有關更多詳細信息,請參閱文檔: https://firebase.google.com/docs/auth/admin/manage-users

暫無
暫無

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

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