我正在尝试通过uid字段从Firebase中删除用户。为此,我正在尝试下面的代码。
Constant.js
import * as admin from "firebase-admin";
admin.initializeApp({
credential: admin.credential.cert({
"type": "service_account",
"project_id": "XXXXXXXXXX",
"private_key_id": "XXXXXXXXXX",
"private_key": "XXXXXXXXXXXX",
"client_email": "XXXXXXXXXXX",
"client_id": "XXXXXXXXXX",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "XXXX"
}),
databaseURL: "XXXXXXXXXX"
});
export const firebaseAdmin = admin;
Auth.js
firebaseAdmin.auth().deleteUser(uid)
.then(function() {
console.log("Successfully deleted user");
})
.catch(function(error) {
console.log("Error deleting user:", error);
});
在上面的示例中。它总是会捕获并显示错误。
错误
删除用户时出错:错误:“提供了凭据实现 通过“ credential”属性的initializeApp()无法获取有效的 Google OAuth2访问令牌,出现以下错误:“无法解析 访问令牌响应:错误:发出请求时出错:不正确 标头检查。错误代码:Z_DATA_ERROR”。”
FirebaseError http://localhost:3000/static/js/0.chunk.js:161518:17 PrefixedFirebaseError http://localhost:3000/static/js/0.chunk.js:161575:17 FirebaseAppError http://localhost:3000/static/js/0.chunk.js:161620:17 cachedTokenPromise_ http://localhost:3000/static/js/0.chunk.js:157209:15