简体   繁体   English

删除firebase中的用户

[英]Delete users in firebase

I have a function that deletes the current logged in user:我有一个 function 删除当前登录的用户:

auth.currentUser.delete().then(logoutOfApp)
.catch((error) => alert(error)));

It works just fine, but I want to make someone an admin, so I would like him to have an option to delete other accounts, so is there a way to do something like this?它工作得很好,但我想让某人成为管理员,所以我希望他可以选择删除其他帐户,那么有没有办法做这样的事情?

auth.something(UserID of the user that i want to delete).delete()

Use firebase-admin NPM package in your backend;在后端使用 firebase-admin NPM package;

app.get('/delete', function (req, res) {
 const sessionCookie = req.cookies.session || '';
 res.clearCookie('session');
 if (sessionCookie) {
  // Verify user and then delete the user.
  admin.auth().verifySessionCookie(sessionCookie, true).then(function(decodedClaims) {
   return admin.auth().deleteUser(userIdToDelete);
  })
  .then(function() {
   // Redirect to login page on success.
   res.redirect('/');
  })
  .catch(function() {
   // Redirect to login page on error.
   res.redirect('/');
  });
 } else {
  // Redirect to login page when no session cookie available.
  res.redirect('/');
 }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM