This is a sort of sample code that I whipped up from an old project.
In your view, you have to use an input to get the role when the user first signs up. Then pass it over to this function which would upload it to firebase
static func createProfile(userId: String, username: String, role: String, completion: @escaping (PhotoUser?) -> Void) {
let profileData = ["username": username, "role": role]// <----- You add a role property to the profile data dict which you would upload to firebase
let db = Firestore.firestore()
db.collection("users").document(userId).setData(profileData) { error in
if error == nil {
// Succesfully created profile
// Create and return a photo user
let user = PhotoUser(userId: userId, username: username)
completion(user)
} else {
// There was an error
print("Couldnt create profile")
print(error!.localizedDescription)
completion(nil)
}
}
}
This would give a database which looks like:
You can then check the user after login using something like this:
if currentUser.role == "admin" {
// Show admin view over here
} else {
// Show normal view over here
}
Note that this is a very high-level visualization of how to implement this, and it probably won’t work if u just copy and paste this. Since You are in the firebase courses, I assume you already know how to get the input from the user and how show different views conditionally