I'm trying to create a API and i want to use firebase.auth() for a signup endpoint in firebase functions with Express, but i cant find a way to get it working, this is what i have:
const functions = require("firebase-functions");
const admin = require('firebase-admin');
const app = require('express')();
admin.initializeApp();
const config = {
//key
};
const db = admin.firestore();
const firebase = require('firebase/app');
firebase.initializeApp(config);
require('firebase/auth')
//singup route
app.post('/signup', (req, res) =>{
const newUser = {
email: req.body.email,
password: req.body.password,
confirmPass : req.body.password,
nickName: req.body.nickName
}
//todo validate data
firebase.auth().createUserWithEmailAndPassword(newUser.email, newUser.password)
.then(data => {
return res.status(200).json({message: `user ${data.user.uid} sign up siccesfully`});
})
.catch(err => {
console.error(err);
return res.status(500).json({error : err.code});
})
});
Exist a way to acomplish this?
Notes : i tried using import, but firebase-functions doesnt work.
When i do a request in postman i get this error:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>TypeError: firebase.auth is not a function<br> at
And nothing happend in firebase, then i want to be hable to create a user using my API, and return the token