facebook facebook-login ios swift swiftui

How to login to Facebook on SwiftUI?

There are not many resources explaining Facebook Login with SwiftUI. I’m not sure whether my code requires a ViewController or not because Facebook’s LoginManager.login() contains a ViewController parameter – however this doesn’t really translate to SwiftUI.

Regardless, I am trying to login the user to Facebook when they click on the Button below:


import Foundation
import SwiftUI
import FBSDKLoginKit
struct LoginView: View {
@EnvironmentObject var auth: UserAuth
var body: some View {
ZStack {
VStack {
.frame(height: 100)
.padding(.top, 100)
Button(action: {
}) {
Text("Continue with Facebook")

when the Button is clicked, it initialises FBLogin below – which fires login() in its init():


class FBLogin: LoginManager {
let loginButton = FBLoginButton()
let token = AccessToken.current
let permissions = ["user_birthday", "user_gender", "public_profile"]
override init(){
logIn(permissions: permissions, from: nil)
print("fb init()")
override func logIn(permissions: [String], from fromViewController: UIViewController?, handler: LoginManagerLoginResultBlock? = nil) {

However I’m not sure what to do from there. At the moment, only fb init() prints but I want to execute the login and listen to the login result.

Any idea?