I'm working on email + password authentication on Firebase Auth + Next js. But I would like to use a dedicated uid for authentication this time. So I think I should use createUser better than createUserWithEmailAndPassword. However, the error occurs like below:
Property 'createUser' does not exist on type 'Auth'.
import { getAuth, createUserWithEmailAndPassword } from 'firebase/auth'
const auth = getAuth()
const newId = XXXXXXXXXXXXXx
getAuth()
.createUser({
uid: newId,
email: data.email,
password: data.password,
})
.then((userRecord) => {
// See the UserRecord reference doc for the contents of userRecord.
console.log('Successfully created new user:', userRecord.uid);
})
.catch((error) => {
console.log('Error creating new user:', error);
});
// It works
createUserWithEmailAndPassword(auth, data.email, data.password)
To createUser you need to use firebase-admin SDK.
With node.js, install it with npm install firebase-admin. Then:
const admin = require("firebase-admin");
const newId = XXXXXXXXXXXXXx;
admin.auth().createUser({
uid: newId,
email: data.email,
password: data.password,
})
.then(function(userRecord) {
// See the UserRecord reference doc for the contents of userRecord.
console.log("Successfully created new user:", userRecord.uid);
})
.catch(function(error) {
console.log("Error creating new user:", error);
});