react-oidc-context icon indicating copy to clipboard operation
react-oidc-context copied to clipboard

expose signinCallback for native applications

Open tmo207 opened this issue 1 year ago • 1 comments

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

tmo207 avatar Aug 08 '24 20:08 tmo207

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...

pamapa avatar Aug 20 '24 13:08 pamapa

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 avatar Sep 19 '24 17:09 taszilvo

@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...

pamapa avatar Sep 20 '24 12:09 pamapa

You're right, passing the UserManager from outside and calling signInCallback on it works. Thanks for the help!

tmo207 avatar Dec 16 '24 18:12 tmo207

I also would have liked to have seen this PR merged or worked on as a fix for Capacitor apps...

Canuckaholic avatar Feb 10 '25 19:02 Canuckaholic

@tmo207 could you provide some instructions on how you got that working?

5t33 avatar Jul 12 '25 16:07 5t33