Admin SDK + Vue Js 列出所有用户?
Admin SDK + Vuejs ListAllUsers?
我已经阅读了有关通过 admin SDK 列出所有用户的文档,但仍然难以在我的 vue 组件中显示用户...
文档中的代码是:
function listAllUsers(nextPageToken) {
// List batch of users, 1000 at a time.
admin.auth().listUsers(1000, nextPageToken)
.then(function(listUsersResult) {
listUsersResult.users.forEach(function(userRecord) {
console.log('user', userRecord.toJSON());
});
if (listUsersResult.pageToken) {
// List next batch of users.
listAllUsers(listUsersResult.pageToken);
}
})
.catch(function(error) {
console.log('Error listing users:', error);
});
});
// Start listing users from the beginning, 1000 at a time.
listAllUsers();
在我的组件中,我想创建一个包含所有用户并显示它们的数组,..问题是,..我该怎么做?是通过 axios 请求吗?步骤是什么?
如 documentation "the Admin SDK supports Node.js, Java, and Python." 中所述,这意味着您不能直接在 Vue.js 组件中使用问题中的代码。您需要在后端执行此代码并从 Vue.js 组件调用此后端。
标准解决方案之一是创建 Callable Cloud Function that executes this code and returns the list of users as an array. The documentation explains how to implement such a function and how to call it from your vue.js application (See here).
您也可以使用 "standard" HTTPS Cloud Function 并通过 Axios 调用它,但是使用 Callable Cloud Functions 会带来一些额外的优势,如文档中所述("Firebase Authentication and FCM tokensare automatically included in requests, the functions.https.onCall trigger automatically deserializes the request body and validates auth tokens.",等等。 ..).
我已经阅读了有关通过 admin SDK 列出所有用户的文档,但仍然难以在我的 vue 组件中显示用户...
文档中的代码是:
function listAllUsers(nextPageToken) {
// List batch of users, 1000 at a time.
admin.auth().listUsers(1000, nextPageToken)
.then(function(listUsersResult) {
listUsersResult.users.forEach(function(userRecord) {
console.log('user', userRecord.toJSON());
});
if (listUsersResult.pageToken) {
// List next batch of users.
listAllUsers(listUsersResult.pageToken);
}
})
.catch(function(error) {
console.log('Error listing users:', error);
});
});
// Start listing users from the beginning, 1000 at a time.
listAllUsers();
在我的组件中,我想创建一个包含所有用户并显示它们的数组,..问题是,..我该怎么做?是通过 axios 请求吗?步骤是什么?
如 documentation "the Admin SDK supports Node.js, Java, and Python." 中所述,这意味着您不能直接在 Vue.js 组件中使用问题中的代码。您需要在后端执行此代码并从 Vue.js 组件调用此后端。
标准解决方案之一是创建 Callable Cloud Function that executes this code and returns the list of users as an array. The documentation explains how to implement such a function and how to call it from your vue.js application (See here).
您也可以使用 "standard" HTTPS Cloud Function 并通过 Axios 调用它,但是使用 Callable Cloud Functions 会带来一些额外的优势,如文档中所述("Firebase Authentication and FCM tokensare automatically included in requests, the functions.https.onCall trigger automatically deserializes the request body and validates auth tokens.",等等。 ..).