I'm new to coding and have been building an app for the last few weeks. I am a little stuck and not sure where to start looking. I have an app that can message between users, have social media pages, and show all users in the app. I have an addition tab that I would like to grant 2 users admin privileges. The other users have access to the same tab but see different things.
I have a json tree that looks like the following:
users
|
|
|
Jjhi848hjnef8
|
|
|
name:
email:
profileImageUrl:
ETC:
I also have a messages tree, as well as user messages tree. I don't want to have to make a new json tree with users and then setup up sub categories of roles because I want all users to be able to message each other and have access to the same stuff except one view controller in the tabbed app. Is there a way to accomplish this cleanly/effectively so I don't have to recode messages, profile, and all users tab?
Here is the code I am trying to run:
import UIKit
import Firebase
class ToDoViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
checkIfAdmin()
}
func checkIfAdmin() {
Database.database().reference().child("users").child(Auth.auth().currentUser!.uid).child("userType").observeSingleEvent(of: .value, with: {
(snapshot) in
switch snapshot.value as! String {
// If our user is admin...
case "Admin":
// ...redirect to the admin page
guard let vc = self.storyboard?.instantiateViewController(withIdentifier: "AdminVC") else { return }
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: true)
// If out user is a regular user...
case "Talent":
// ...redirect to the talent page
guard let vc = self.storyboard?.instantiateViewController(withIdentifier: "TalentVC") else { return }
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: true)
// If the type wasn't found...
default:
// ...print an error
print("Error: Couldn't find type for user")
}
})
}
}
My userType node has either Admin or Talent as the value. I am trying to get users that have been marked admin to see a specific view controller in my tab controller. I now can see the different pages but I am getting a glitch where it shows the view controller modally and it is constantly reloading the page and won't stop moving. If I turn animation to false it gets stuck and won't allow for any interactivity.
It's hard to tell why that happens just by looking at this code snippet. I think you should upload also the code of the TalentVC view controller