Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on firebase require in node JS #271

Open
ahmad1508 opened this issue Feb 11, 2022 · 0 comments
Open

Error on firebase require in node JS #271

ahmad1508 opened this issue Feb 11, 2022 · 0 comments

Comments

@ahmad1508
Copy link

ahmad1508 commented Feb 11, 2022

I'm trying to use firebase auth in the backend for authentification i tried to follow the firebase documentation to import these functions which does not work for nodeJS

import { getAuth, createUserWithEmailAndPassword } from "firebase/auth";
const auth = getAuth();
createUserWithEmailAndPassword(auth, email, password)
  .then((userCredential) => {
    Signed in 
    const user = userCredential.user;
  })
  .catch((error) => {
    const errorCode = error.code;
    const errorMessage = error.message;  });

i tried to change the into a const ... = require() instead of an import
but now i'm getting this error
FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).

if i use the old version with firebase 8 requiring firebase i'm getting this error,
[Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" - Firebase](https://stackoverflow.com/questions/69200493/error-err-package-path-not-exported-no-exports-firebase)

i'm trying to create a user in a express app endpoint:

   app.post('/signup', (req, res) => {
    const newUser = {
        email: req.body.email,
        password: req.body.password,
        confirmPassword: req.body.confirmPassword,
        handle: req.body.handle,
    }

    createUserWithEmailAndPassword(auth, newUser.email, newUser.password)
        .then(data => {
            return res.status(201).json({ message: `user${data.user.uid} signed up succesfully` })
        })
        .catch(err => {
            console.error(err)
            return res.status(500).json({ error: err.code })
        })
   })

How can i solve my problem ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant