Hello
I have an SSR react app (Express) and my lambda functions work fine and all but connecting to the Firebase Real-Time database is a struggle. Google many answers which of none works.
I get several errors such as init standalone is not a function and “IDBIndex is not defined’,”
here is my code: (lamda fn)
import * as admin from 'firebase-admin'
const serviceAccount = require('../../my-saas-XXX.json')
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: 'https://my-saas.firebaseio.com',
})
export async function handler(event, context) {
const body = JSON.parse(event.body)
const {
email,
password,
name,
organisation,
logo,
phone,
address,
homepage,
option,
} = body
console.log('body:::::::::::::::::::', body)
const user = {
email,
name,
organisation,
logo,
phone,
address,
homepage,
option,
admin: false,
key_li: '',
key_ga: '',
}
const db = admin.database()
// console.log(db)
console.log('user', user)
return await admin
.auth()
.createUser({
email: email,
emailVerified: false,
phoneNumber: phone,
password: password,
displayName: name,
photoURL: 'http://www.example.com/12345678/photo.png',
disabled: false,
})
.then((usr) => {
db.ref('users/' + usr.uid)
.set(user)
.then(console.log('uid', usr.uid))
.catch((error) => {
console.log(error.message)
})
return {
statusCode: 200,
body: JSON.stringify({ data: usr.uid }),
}
})
.catch((e) => {
return {
statusCode: 500,
body: JSON.stringify({ data: e.message }),
}
})
}
I added a webpack.config.js which stance
module.exports = {
resolve: {
mainFields: ['main', 'module'],
},
}