9

I'm developming simple React application which uses firebase admin.

I have generated react application by using create react app.

Then I have installed firebase-admin by using this npm command:

npm install firebase-admin --save

In my index.js I have added this import:

 import React from 'react';
 import ReactDOM from 'react-dom';
 import App from './App';
 import registerServiceWorker from './registerServiceWorker';

 import * as admin from 'firebase-admin'

 ReactDOM.render(<App />, document.getElementById('root'));
 registerServiceWorker();

When I launch with npm start command and open my page I get this error:

 Module not found: Can't resolve 'dns' in 'D:\path\to\my\project\node_modules\firebase-admin\node_modules\isemail\lib'

Why this is happening? Did I miss something?

KENdi
  • 7,576
  • 2
  • 16
  • 31
Mr.D
  • 7,353
  • 13
  • 60
  • 119

1 Answers1

11

Admin SDKs cannot be used in client-side environments. That includes web browsers. Admin SDKs can and should only be used in privileged server environments owned or managed by the developers of a Firebase app. You should use the Firebase web SDK in your React app.

Hiranya Jayathilaka
  • 7,180
  • 1
  • 23
  • 34
  • 1
    Gee, i don't see that detail in the docs. So if i were building some type of admin interface that allowed admins to view all users for example of my firebase instance, i would need to just make that a regular user within my app to grant browser-side control? Thus I'd have a collection of admins in my firebase instance? Admin SDK is for basically server-side only stuff (ie cloud functions)? Right? – AlxVallejo Oct 03 '17 at 18:41
  • 2
    Correct. You can host some privileged operations in a server (using admin SDK), and get your client-side app to contact the server when those operations are needed. You can use `admin.auth().verifyIdToken()` in the server to validate the requests. – Hiranya Jayathilaka Oct 03 '17 at 20:10