Hi all,
Im somewhat new to SwiftUI and have encountered something i cannot fix myself.
So im working with SwiftUI. And have successfully created a login page with firebase facebook authentication.
And all the functionalities work just fine, but i would like to customise the default/built-in login/logout button.
Would really appreciate some help
This is the code i use for authentication:
import SwiftUI
import FBSDKLoginKit
import Firebase
struct LoginView : UIViewRepresentable {
func makeCoordinator() -> LoginView.Coordinator {
return LoginView.Coordinator()
}
func makeUIView(context: UIViewRepresentableContext<LoginView>) -> FBLoginButton {
let button = FBLoginButton()
button.permissions = ["email", "public_profile"]
button.delegate = context.coordinator
return button
}
func updateUIView(_ uiView: FBLoginButton, context: UIViewRepresentableContext<LoginView>) {
}
class Coordinator : NSObject, ObservableObject,LoginButtonDelegate{
func loginButtonDidLogOut(_ loginButton: FBLoginButton) {
try! Auth.auth().signOut()
print("Did logout")
}
func loginButton(_ loginButton: FBLoginButton, didCompleteWith result: LoginManagerLoginResult?, error: Error?) {
if error != nil {
print((error?.localizedDescription)!)
return
}
if AccessToken.current != nil {
let credential = FacebookAuthProvider.credential(withAccessToken: AccessToken.current!.tokenString)
Auth.auth().signIn(with: credential) {(res , er) in
if er != nil{
print((er?.localizedDescription)!)
return
}
print("SUCCES!")
}
}
}
}
}