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

fix: allows OTP to be approved from a cold start #1256

Merged
merged 6 commits into from
Aug 16, 2023

Conversation

williamlines
Copy link
Contributor

Adds a conditional to the notification listener useEffect to use the necessary callbacks when a OTP request is pressed whilst the app is closed.

closes: #1155

@github-actions
Copy link

github-actions bot commented Aug 15, 2023

Preview available at https://expo.dev/accounts/nearform/projects/optic-expo/updates/4648bf54-ef79-47cc-9504-970895943719

Or scan QR Codes...

android:
QR Code

ios:
QR Code}

@williamlines
Copy link
Contributor Author

This is currently not working on IOS

@williamlines williamlines marked this pull request as draft August 15, 2023 12:29
Copy link
Member

@simoneb simoneb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gut feeling when looking at this change is that there should be a more straightforward way to achieve what we want. The assumption is that we're not doing anything fancy with push notifications, we just need to open the app when we get one, open the app in a specific "state".

Hence, I have a feeling that if it requires a solution like this one, which is moderately complex and error prone, there's a good chance we're doing something wrong.

On the other hand I don't have a solution either, but I would try to spend some time trying to understand what the root problem is rather than trying patching the issue.

@williamlines
Copy link
Contributor Author

I have done some more research for alternative solutions since learning that this approach is possibly non-viable for IOS, I have a lead for a solution that feels less hacky, by using the NotificationResponseReceivedListener, the docs suggest that this should be able to use the notification from a cold start, need to figure out the implementation.

Screenshot 2023-08-15 at 15 18 44

@simoneb
Copy link
Member

simoneb commented Aug 15, 2023

Good lead Will, worth investigating

@williamlines
Copy link
Contributor Author

The problem currently is that the notification is consumed to open the app, before the listeners are active, hopefully the NotificationResponseReceivedListener should be able to catch the notification.

@simoneb
Copy link
Member

simoneb commented Aug 15, 2023

I am not terribly familiar with how this issue manifests itself, but in the app we have a notifications section. If we managed to go in there and keep the notification visible in the list, it may be an acceptable compromise. But I'm just making this up now, let's definitely investigate what seems to be a more appropriate solution

@williamlines
Copy link
Contributor Author

In the case of both adding a notification to the list and displaying the 2FA challenge, there is the same difficulty of having to 'catch' the notification before the app starts up, or it gets lost. My feeling is that such a compromise likely won't save much effort. I will see how this listener behaves before jumping to conclusions

@williamlines
Copy link
Contributor Author

Upon investigating, it seems like this implementation is the same as what we currently have. The docs would suggest that this implementation should work for our needs but it seems like this is not the case, see:
expo/expo#14078
The solution many suggest in this thread is similar to what I have done here, as far as I can find there isn't a much better solution.

@williamlines williamlines marked this pull request as ready for review August 16, 2023 09:25
src/screens/HomeScreen.tsx Outdated Show resolved Hide resolved

return (
<InitialLoadingContext.Provider
value={{ initialLoadingComplete, markInitialLoadingComplete }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer memoizing this object, otherwise each render of this component will create a new object, which will cause a rerender of all users of this context, which is unnecessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved in 9a2f856

Copy link
Member

@simoneb simoneb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@williamlines williamlines merged commit 5a6291a into master Aug 16, 2023
6 checks passed
@williamlines williamlines deleted the fix/open-app-from-notification-when-closed branch August 16, 2023 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Opening app from notification when fully closed can swallow the notification
2 participants