Member-only story
I’ll admit it. I will NEVER get tired of that feeling you get when a new user signs up for your application. In some cases, this feels better than earning money on it. Yup, I said it!
What I do get tired of, is revisiting the Firebase authentication page, to check if a new user has signed up. At the beginning of a new project, I probably visit the authentications page every 30 minutes. And it is a bit disappointing every time you’ll see no new sign-ups.
So let’s make a small script to avoid this. In this case, NextJS and Firebase are required.
const signup = async(userName, email, password) => {
const auth = getAuth();
createUserWithEmailAndPassword(auth, email, password).then((res)
=> {
fetch("/api/registration", {
method: "POST",
headers: {
Accept: "application/json, text/plain, */*",
"Content-Type": "application/json",
},
body: JSON.stringify({ userName, email })
}).then((e) => console.log(e)).catch((err) => console.log(err));
})}
The signup function itself is using the createUserWithEmailAndPassword as we are familiar with from firebase. The only thing we add is the fetch function calling our API, which we will create in our NextJS app. In our notification, we will see the new user's email and user name.