I try to keep the User logged in without using firebase. I look up different posts and couldn't find the right way to do it other than if I use the firebase.
@IBAction func LoginTapped(_ sender: Any) {
let authService = AuthenticationService()
emailTextfield.resignFirstResponder()
passwordTextfield.resignFirstResponder()
authService.loginUser(email: email, password: password) { (isManager) in
if let isManager = isManager {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
DispatchQueue.main.async {
var viewController:UIViewController
if isManager{
viewController = storyboard.instantiateViewController(identifier: "managerEntryViewController")
}else{
viewController = storyboard.instantiateViewController(identifier: "clientEntryViewController")
}
viewController.modalPresentationStyle = .fullScreen
self.present(viewController, animated: true)
}
} else {
DispatchQueue.main.async {
self.alertError()
}
}
}
}
In the AuthenticationService() there is already function created where the token is created for users who already signed in. I want to create logic where I if token valid or not.
fileprivate func saveToken(token: String) {
UserDefaults.standard.set(token, forKey: NetworkConstants.tokenKey)
}
This current Login function uses "authService" as a way to communicate with backend to pass email and password. Is it possible I can keep the user logged after the user went to the main screen in Xcode without using firebase? or it needs to be something done at the backend. Let me know if you need any additional explanations! I am happy to clarify!