oidc-client-ts icon indicating copy to clipboard operation
oidc-client-ts copied to clipboard

How to use UserManager with HashRouter in React?

Open HanCai98 opened this issue 2 years ago • 4 comments

Hi, I am working on a React project, and need to use auth service. Previously, I used BrowserRouter, everything is good. But for some reason, I need to change to use HashRouter, but this time, the login page seems get stuck. Does anyone have any idea? Really appreciate it!

Screen Shot 2022-09-01 at 23 37 25 Screen Shot 2022-09-01 at 23 38 05 Screen Shot 2022-09-01 at 23 38 15

HanCai98 avatar Sep 02 '22 03:09 HanCai98

Have you checked in the settings: response_mode: "query" vs "fragment"

pamapa avatar Sep 02 '22 06:09 pamapa

Hi, @pamapa, thanks for your advice, I try to change my userManager settings (shown as below), but my login page still get stuck, in the browser, I have this error:

react_devtools_backend.js:4026 No routes matched location "code=qamaster_1963BE7834DB682D5011CD4D0C8E53CD21C62AE8166C5B0447FDB2AE722C9ED3&scope=openid%20profile&state=f834eb900d464ae2a9b123ef61297e02&session_state=ayY2RUc4OCX-2X4wUVyH2DVmmZ54BD4kmfMonsvXBGI.r-8Lg6TouvpkKhDfLNrhIQ"  
    at Routes (http://localhost:3000/static/js/bundle.js:59491:5)
    at AuthProvider (http://localhost:3000/main.45a79611680d96b316ae.hot-update.js:66:5)
    at Router (http://localhost:3000/static/js/bundle.js:59424:15)
    at HashRouter (http://localhost:3000/static/js/bundle.js:58267:5)
    at App
Screen Shot 2022-09-02 at 10 06 02

HanCai98 avatar Sep 02 '22 14:09 HanCai98

Add when I changed the response_type from code to token, I have an error like this

Uncaught (in promise) Error: Only the Authorization Code flow (with PKCE) is supported
    at OidcClient.createSigninRequest (bundle.js:109124:13)
    at UserManager._signinStart (bundle.js:110438:48)
    at UserManager._signin (bundle.js:110430:36)
    at UserManager.signinPopup (bundle.js:110216:29)

HanCai98 avatar Sep 02 '22 14:09 HanCai98

No routes matched location i guess that is routing problem of your own application. You need to ensure that this can be handled...

pamapa avatar Sep 05 '22 06:09 pamapa

see solution i found and put in https://github.com/authts/oidc-client-ts/issues/734 then you can keep the default response mode for the sts service which y probably need to be 'query'. sombody else should create a PR for this

frontendplace avatar Oct 25 '22 11:10 frontendplace