Skip to content

Commit

Permalink
fix: android custom tabs dismiss callback (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
nattb8 authored Jan 25, 2024
1 parent 2a71c8d commit 9b6276d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
15 changes: 12 additions & 3 deletions Source/Immutable/Private/Immutable/ImmutablePassport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ void UImmutablePassport::OnConnectPKCEResponse(FImtblJSResponse Response)
{
IMTBL_ERR("Unable to return a response for Connect PKCE");
}
ResetStateFlags(IPS_COMPLETING_PKCE);
}
#endif

Expand Down Expand Up @@ -958,7 +959,10 @@ void UImmutablePassport::OnDeepLinkActivated(FString DeepLink)

void UImmutablePassport::CompleteLoginPKCEFlow(FString Url)
{
SetStateFlags(IPS_CONNECTED);
// Required mainly for Android to detect when Chrome Custom tabs is dismissed
// See HandleOnLoginPKCEDismissed
SetStateFlags(IPS_COMPLETING_PKCE);

// Get code and state from deeplink URL
TOptional<FString> Code, State;
FString Endpoint, Params;
Expand Down Expand Up @@ -989,7 +993,7 @@ void UImmutablePassport::CompleteLoginPKCEFlow(FString Url)
IMTBL_ERR("%s", *ErrorMsg);
PKCEResponseDelegate.ExecuteIfBound(FImmutablePassportResult{false, ErrorMsg});
PKCEResponseDelegate = nullptr;
ResetStateFlags(IPS_PKCE|IPS_CONNECTING);
ResetStateFlags(IPS_PKCE|IPS_CONNECTING|IPS_COMPLETING_PKCE);
}
else
{
Expand Down Expand Up @@ -1028,7 +1032,12 @@ void UImmutablePassport::HandleOnLoginPKCEDismissed()
IMTBL_LOG("Handle On Login PKCE Dismissed");
OnPKCEDismissed = nullptr;

if (IsStateFlagSet(IPS_CONNECTING))
// If the second part of PKCE (CompleteLoginPKCEFlow) has not started yet and custom tabs is dismissed,
// this means the user manually dismissed the custom tabs before entering all
// all required details (e.g. email address) into Passport
// Cannot use IPS_CONNECTING as that is set when PKCE flow is initiated. Here we are checking against the second
// half of the PKCE flow.
if (!IsStateFlagSet(IPS_COMPLETING_PKCE))
{
// User hasn't entered all required details (e.g. email address) into
// Passport yet
Expand Down
3 changes: 2 additions & 1 deletion Source/Immutable/Public/Immutable/ImmutablePassport.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ class IMMUTABLE_API UImmutablePassport : public UObject
IPS_CONNECTED = 1 << 1,
IPS_IMX = 1 << 2,
IPS_PKCE = 1 << 3,
IPS_INITIALIZED = 1 << 4
IPS_COMPLETING_PKCE = 1 << 4,
IPS_INITIALIZED = 1 << 5
};

uint8 StateFlags = IPS_NONE;
Expand Down

0 comments on commit 9b6276d

Please sign in to comment.