1
votes

I'm developing an app on iOS with Firebase Auth and Facebook. I want to use Facebook graph sdk after login with Facebook. It's working fine the first time. But when I re-launch the app, the graph API don't work :

An active access token must be used to query information about the current user.

and the following code is nil :

FBSDKAccessToken.current()?.tokenString

BUT the user is logged with Firebase Auth :

// check if user is logged
FIRAuth.auth()?.addStateDidChangeListener({ (auth, user) in
    if user != nil{
        print("User logged") ...

Is there a way to get the current Facebook access token via Firebase Auth ? Or I have to persist the access token for using it later ? Or re-log user each time (not user friendly at all) ?

My solution (but don't know if best way) :

  1. save "access token" in firebase database at fb login
  2. when app restart, get the persisted "access token" from database
  3. check if the "access token" is still valid
  4. if not, re-log user and get a new "access token" and save it

Update

I noticed that i was getting this message :

Falling back to loading access token from NSUserDefaults because of simulator bug

so I checked my code in a real device, and it's working now, the access token is persisted through the app relaunch.

1

1 Answers

1
votes

I noticed that I was getting this message :

Falling back to loading access token from NSUserDefaults because of simulator bug

so I checked my code in a real device, and it's working now, the access token is persisted through the app relaunch.