-4

How to retrieve user list from fire base authentication? I want to retrieve all register user list. When I'm using listAllUsers()-function, I get a message that "admin is not defined".

I'm using this function:

function listAllUsers(nextPageToken) {
  admin.auth().listUsers(1000, nextPageToken)
    .then(function(listUsersResult) {
        listUsersResult.users.forEach(function(userRecord) {
            console.log('user', userRecord.toJSON());
        });
        if (listUsersResult.pageToken) {
            listAllUsers(listUsersResult.pageToken);
        }
    })
    .catch(function(error) {
          console.log('Error listing users:', error);
    });
}
Dinesh Shingadiya
  • 988
  • 1
  • 8
  • 23
prabhat
  • 11
  • 4

3 Answers3

0

Check everything is imported first. Then Clear the config cache php artisan config:clear or rebuild it php artisan config:cache.

  • i am not using in php that is javascript code i am using firebase – prabhat May 28 '19 at 05:25
  • did you imported the Admin SDK module?. – sarath s rajendran May 28 '19 at 05:26
  • const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase); Check https://github.com/firebase/functions-samples/blob/master/quickstarts/uppercase/functions/index.js#L22-L23 OR https://firebase.google.com/docs/functions/get-started#import_the_required_modules_and_initialize for more information – sarath s rajendran May 28 '19 at 05:38
  • how can i retrieve all user from my firebase authentication i have lot's of user in my firebase auth. now i want to see on my web page all user in a list how can i get please provide me suggestion and code. i am using java script in my project. – prabhat May 28 '19 at 08:45
0

@prabhat make sure you have included the require libraries in your application.

<body>
  <!-- Insert these scripts at the bottom of the HTML, but before you use any Firebase services -->

  <!-- Firebase App (the core Firebase SDK) is always required and must be listed first -->
  <script src="https://www.gstatic.com/firebasejs/6.0.4/firebase-app.js"></script>

  <!-- Add Firebase products that you want to use -->
  <script src="https://www.gstatic.com/firebasejs/6.0.4/firebase-auth.js"></script>
  <script src="https://www.gstatic.com/firebasejs/6.0.4/firebase-firestore.js"></script>
<body>

Here is the link for the reference: https://firebase.google.com/docs/web/setup#libraries_CDN

Try change admin with firebase if it not works... do setup the code with node modules.

https://firebase.google.com/docs/admin/setup#add_the_sdk

npm install firebase-admin --save

// To use the module in your application, require it from any JavaScript file:

var admin = require('firebase-admin');

import * as admin from 'firebase-admin';
Vikash Pathak
  • 3,444
  • 1
  • 18
  • 32
  • sir i have all ready include all require libraries in my application – prabhat May 28 '19 at 05:38
  • So you have locally downloaded the library in your system correct? – Vikash Pathak May 28 '19 at 05:39
  • @prabhat try change `admin` with `firebase`..if it works else you'll have to use the node modules for the admin sdk. – Vikash Pathak May 28 '19 at 05:48
  • If it not works.. please follow these instruction to setup this with node app.. https://firebase.google.com/docs/admin/setup#add_the_sdk – Vikash Pathak May 28 '19 at 05:49
  • sir after using this error is {Uncaught SyntaxError: Unexpected token *} – prabhat May 28 '19 at 05:56
  • @prabhat need more claritly how you are going to use the firbase sdk... are you going to use with node application or PHP? if going to use with php better to use https://firebase-php.readthedocs.io/en/latest/overview.html#usage-example else...if you are trying with Nodejs... do follow the instrcution that I have provided in solution. – Vikash Pathak May 28 '19 at 06:20
  • i am using with node – prabhat May 28 '19 at 07:39
  • That awesome! follow this https://firebase.google.com/docs/admin/setup#add_the_sdk – Vikash Pathak May 28 '19 at 07:44
  • how can i retrieve all user from my firebase authentication i have lot's of user in my firebase auth. now i want to see on my web page all user in a list how can i get please provide me suggestion and code. i am using java script in my project. – prabhat May 28 '19 at 08:45
0

There is no API to get a list of all users from Firebase Authentication for use in a web page. If you want to show a list of users in your web page, you will either have to store that list in a database you can access from the web page (like the Firebase Realtime Database or Cloud Firestore), or use the Firebase Admin SDK in a trusted environment (such as a server you control, or Cloud Functions), and to build your own API, and then call that API from your web page.

See these previous questions for more on this:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807