Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

16.0.1 FB SDK doesn't keep user logged in on subsequent sessions #695

Open
5 tasks done
vnavarro opened this issue Aug 7, 2023 · 8 comments
Open
5 tasks done

16.0.1 FB SDK doesn't keep user logged in on subsequent sessions #695

vnavarro opened this issue Aug 7, 2023 · 8 comments
Labels

Comments

@vnavarro
Copy link

vnavarro commented Aug 7, 2023

Hi,

I've already opened it on a previous channel but was wrongly dismissed

https://developers.facebook.com/support/bugs/297755336112477/

So, I will give all info here.

Checklist

Environment

Unity Editor Version: 2021.3.25f1
Unity FB SDK 16.0.1
Builds: iOS and Android. Any version.

Goals

Use FB Login with a user-provided FB account so user will be logged in with FB in the game.

Expected Results

After the user logs in with Facebook login is not requested from the user until the token is expired, regardless of the game being closed.

Actual Results

The user logs in and has a valid non-expired access token with further away expiration in the future, when the game is closed and opened again FB SDK does not identify the user being logged in so it will ask the user for login again, no matter how many times it does never save it.

Steps to Reproduce

1 - Create Unity project and add FB SDK (16.0.1) to it (iOS/Android devices)
2 - Initialize Facebook SDK (FB.Init) and ask user to login FB.LogInWithReadPermissions use gaming_profile permission
3 - With the user successfully logged in close and kill the game
4 - Reopen the game, and check that after initializing facebook it still needs login (FB.IsInitialized = true and FB.IsLoggedIn = false)

Code Samples & Details

FB.Init(onInitComplete: () => {
  if (!FB.IsLoggedIn)
  {
    FB.LogInWithReadPermissions(FacebookSDKNeededPermissions, result => { });
  }
});
@vnavarro vnavarro added the bug label Aug 7, 2023
@mmunson-aftershock
Copy link

Only a problem with iOS as far as I can tell. The breaking commit was 7ba25ae

@AvivWhalo
Copy link

bump, we're also suffering the same problem

@dreamcodestudio
Copy link

dreamcodestudio commented Aug 30, 2023

Same issue on iOS
after bump Facebook from 15.1.0 to 16.0.1

@MTPirate89
Copy link

bump, we're experiencing same issue after update(

facebook-github-bot pushed a commit that referenced this issue Aug 31, 2023
Summary:
Bug reported in GitHub: #695
"FB SDK doesn't keep user logged in on subsequent sessions". It's only happening in the last release of the SDK and on iOS according to user and partner reports. This diff fixes this issue.

According to the instructions in the iOS SDK (https://github.com/facebook/facebook-ios-sdk/blob/41044df838ef3fefe600fb96b6560dc8a2b2a18a/FBSDKCoreKit/FBSDKCoreKit/ApplicationDelegate.swift#L55-L56), "Do not use the method initializeSDK if you are using the SDK within the context of the 'UIApplication' lifecycle", which is the case of the Unity SDK, "Instead use 'application(_:didFinishLaunchingWithOptions:)'"

Basically, the didFinishLaunchingWithOptions method is called after state restoration has occurred (for example, when the app is launched again after it is suspended or in the background). It is needed to restore the user information, such as the access token.

Reviewed By: GMc14

Differential Revision: D48560401

fbshipit-source-id: 6a6269ad8392db164638e24b04a666c71bfe5c7f
@AdeelAhmed60
Copy link

You need to wait for the main thread after initializing the "FB.Init" Facebook sdk but if error still occur try refreshing current access token after confirming if user logged in
FB.Mobile.RefreshCurrentAccessToken Hope this will help

@lymancao
Copy link

Same issue on iOS for Unity FB SDK 16.0.2

@lymancao
Copy link

You need to wait for the main thread after initializing the "FB.Init" Facebook sdk but if error still occur try refreshing current access token after confirming if user logged in FB.Mobile.RefreshCurrentAccessToken Hope this will help

This is the right answer.

  1. wait a second for FB.IsLoggedIn to become true.
  2. AccessToken.CurrentAccessToken is null now
  3. call FB.Mobile.RefreshCurrentAccessToken to get AccessToken

@dvgco
Copy link

dvgco commented Aug 15, 2024

After the fixed in Unity FB SDK 17.0.1
There are new problem on my side, when logged in subsequent sessions, the AccessToken.CurrentAccessToken is null after FB.Init, then the FB.IsLoggedIn is true but AccessToken.CurrentAccessToken is null on iOS platform.

Finally, I found the reason is that didFinishLaunching in FBUnityInterface.mm called after the FB.Init (Called on awake) on my code, it's caused the AccessToken.CurrentAccessToken keeps null all the runtime if not call FB.Mobile.RefreshCurrentAccessToken to get AccessToken.

This is the order of execution:

  1. call UnityAppController 'didFinishLaunching'
  2. call GameObject awake in Unity (FB.Init here, and then send 'OnInitComplete' message to Unity with null access token)
  3. call FBSDKApplicationDelegate 'didFinishLaunching' (FB initializeSDK here, sync load the accesstoken cache)

I think the right call order should be 1 -> 3 -> 2

why could not FB initializeSDK in IOSFBInit funtion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants