0
0
Firebasecloud~30 mins

User profile data in Firebase - Mini Project: Build & Apply

Choose your learning style9 modes available
User profile data
📖 Scenario: You are building a simple user profile storage system using Firebase Realtime Database. Each user has a unique ID, a name, and an email address.
🎯 Goal: Create a Firebase Realtime Database structure to store user profiles, add a configuration variable for the default user role, write the logic to add a new user profile, and finalize the database rules to secure the data.
📋 What You'll Learn
Create a dictionary called users with two user profiles with exact IDs and data
Add a variable called defaultRole set to "user"
Write a function called addUserProfile that takes userId, name, and email and adds a new user with the defaultRole
Add Firebase Realtime Database rules to allow authenticated users to read and write their own profile only
💡 Why This Matters
🌍 Real World
Storing and managing user profiles securely is essential for many apps and websites. Firebase Realtime Database is a popular backend service for this.
💼 Career
Understanding how to structure user data and secure it with Firebase rules is a key skill for cloud developers and backend engineers.
Progress0 / 4 steps
1
Create initial user profiles
Create a dictionary called users with these exact entries: "user1" with {"name": "Alice", "email": "alice@example.com"} and "user2" with {"name": "Bob", "email": "bob@example.com"}.
Firebase
Need a hint?

Use a dictionary with user IDs as keys and dictionaries with name and email as values.

2
Add default user role configuration
Add a variable called defaultRole and set it to the string "user".
Firebase
Need a hint?

Just create a variable with the exact name and value.

3
Write function to add user profile
Write a function called addUserProfile that takes parameters userId, name, and email. Inside the function, add a new entry to the users dictionary with the given userId and a dictionary containing name, email, and role set to defaultRole.
Firebase
Need a hint?

Define a function with the exact name and parameters, then assign the new user dictionary to users[userId].

4
Add Firebase Realtime Database security rules
Add Firebase Realtime Database rules as a JSON string variable called databaseRules that allows authenticated users to read and write only their own profile under /users/<userId>. Use auth != null and auth.uid == userId conditions.
Firebase
Need a hint?

Use a JSON string with rules for /users/$userId path and conditions for read and write.