expose signinCallback for native applications
Closes/fixes #1216 #1145
Capacitor apps do not trigger signinCallback when returning from the browser to the app. By calling signinCallback manually the user is able to finish authenticaion.
Example:
CapApp.addListener("appUrlOpen", async ({ url }) => {
// TODO: handle URL
...
await auth.callSigninCallback('/some-path' + authParams);
...
});
The problem here is that the AuthState is not updated after the call. The reducer is called with the correct values (isLoading: false, isAuthenticated: true), but the native app needs a manual reload to update the AuthState. Any idea why this might be @pamapa ?
Checklist
- [x] This PR makes changes to the public API
- [x] I have included links for closing relevant issue numbers
The problem here is that the AuthState is not updated after the call. The reducer is called with the correct values (isLoading: false, isAuthenticated: true), but the native app needs a manual reload to update the AuthState. Any idea why this might be?
This MR is more a workaround than a fix and is missing } catch (error) {... and surrounding useCallback(.
The reducer creates a new state, which should be propagated via useReducer, respectively via useAuth into the application. Assuming that within the application the state is not cached (useMemo) i would assume that code element would be re-rendered...
Hey guys @tmo207 @pamapa! I am still curious about the potential fix for the issue with capacitor apps. What happened with this PR? Could you somehow solve the bug at the end?
@taszilvo if you really need it, there is no other way we can add something like this. The name of the new exposed function would be signinCallback. On the other hand if you create the UserManager object outside and pass it into AuthProvider, you can do whatever you like on that object...
You're right, passing the UserManager from outside and calling signInCallback on it works. Thanks for the help!
I also would have liked to have seen this PR merged or worked on as a fix for Capacitor apps...
@tmo207 could you provide some instructions on how you got that working?