Firebase is a platform developed by Google and is popular for developing mobile apps and web projects due to its comprehensive set of tools that speed up development.
We use Firebase to easily implement our backend for user authentication and data storage.
With Firebase Authentication, we are able to sign up and authenticate unique users using their given email address and password. Each user created is then given a unique ID (UID), which we use throughout our application to check features that are for only authenticated users such as writing comments.
The create function creates a new user using the provided email address and password:
const create = async (credentials) => {
const { email, password, name } = credentials;
try {
const { user } = await createUserWithEmailAndPassword(
firebaseAuth,
email,
password,
);
if (user !== null) {
await updateProfile(user, {
displayName: name,
});
return user;
}
} catch (error) {
if (error instanceof FirebaseError) {
switch (error.code) {
case 'auth/email-already-in-use':
console.error('Email is already is use');
break;
case 'auth/invalid-email':
console.error('Email is invalid');
break;
default:
console.error(error);
}
}
console.error('Error creating new user: ', error);
}
};
Additionally, Firebase Authentication throws detailed errors for specific situations such as when a user’s email is already in use. With this information, we can provide more user friendly error messages to the user upon registration.
There are several solutions for data storage provided by Firebase but we choose Firestore for its simpler SDK and to take advantage of its more advanced querying capabilities. For example, we store a sub collection of comments for each section; making it simpler to access and keep all relevant data together.
Also, while the CRUD features of the comments section is fully capable using Realtime Database from Firebase, overall we choose Firestore because of its scalability and support for a growing comments database.

Each section has its own sub-collection of comments