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

expose in-memory copy of userManager

Open rahul-sharma-uipath opened this issue 3 years ago • 2 comments

exposes a copy of userManager that can be used in static contexts - for example to get an access_token or to call logout directly outside of a React component/hook.

Closes/fixes https://github.com/authts/react-oidc-context/issues/313 https://github.com/authts/react-oidc-context/issues/331

Checklist

  • [x] This PR makes changes to the public API
  • [x] I have included links for closing relevant issue numbers

rahul-sharma-uipath avatar Aug 03 '22 20:08 rahul-sharma-uipath

@pamapa / @kherock pls review when you get a chance

rahul-sharma-uipath avatar Aug 03 '22 20:08 rahul-sharma-uipath

@pamapa / @kherock any update?

rahul-sharma-uipath avatar Aug 09 '22 19:08 rahul-sharma-uipath

This implementation works against the existing design, see e.g. how events are exposed. I am not 100% sure if it makes sense to expose the userManager, maybe for unseen use cases like access the metadata (see #465)

@kherock Should we expose the userManager?

pamapa avatar Aug 24 '22 15:08 pamapa

This implementation works against the existing design, see e.g. how events are exposed. I am not 100% sure if it makes sense to expose the userManager, maybe for unseen use cases like access the metadata (see #465)

@kherock Should we expose the userManager?

the reason it doesn't follow the existing design is that this is a unique case of getting a static handle on the userManager outside of the paradigm of React / React Context - ultimately its up to you if you think its an acceptable part of the design, but if not I'm curious how else it could be implemented.

An alternative idea is to simply add the functionality to pass in the userManager and expect adopters of the library to create and manage the lifetime of it

rahul-sharma-uipath avatar Aug 24 '22 17:08 rahul-sharma-uipath

An alternative idea is to simply add the functionality to pass in the userManager and expect adopters of the library to create and manage the lifetime of it

optional passing an instance of the userManager would be acceptable.

pamapa avatar Aug 25 '22 14:08 pamapa

@pamapa changes are ready for review

rahul-sharma-uipath avatar Aug 31 '22 21:08 rahul-sharma-uipath

Codecov Report

Merging #466 (134c8a5) into main (8345d0c) will increase coverage by 0.09%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #466      +/-   ##
==========================================
+ Coverage   88.52%   88.61%   +0.09%     
==========================================
  Files           9        9              
  Lines         122      123       +1     
  Branches       18       19       +1     
==========================================
+ Hits          108      109       +1     
  Misses         11       11              
  Partials        3        3              
Flag Coverage Δ
unittests 88.61% <100.00%> (+0.09%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/AuthProvider.tsx 89.06% <100.00%> (+0.17%) :arrow_up:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

codecov[bot] avatar Sep 06 '22 14:09 codecov[bot]

pipeline fails with:

npm pack --dry-run

> [email protected] prepack
> npm run build


> [email protected] build
> node scripts/build.js && npm run build-types


> [email protected] build-types
> tsc --emitDeclarationOnly && api-extractor run


api-extractor 7.28.0  - https://api-extractor.com/

Using configuration from ./api-extractor.json
Analysis will use the bundled TypeScript version 4.6.4
Warning: src/AuthProvider.tsx:17:1 - (ae-missing-release-tag) "AuthProviderPropsBase" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Warning: src/AuthProvider.tsx:86:1 - (ae-missing-release-tag) "AuthProviderUserManagerProps" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)

Warning: src/AuthProvider.tsx:92:1 - (ae-missing-release-tag) "AuthProviderNoUserManagerProps" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
API Extractor completed with warnings
npm ERR! code 1
npm ERR! path /home/runner/work/react-oidc-context/react-oidc-context
npm ERR! command failed
npm ERR! command sh /tmp/prepack-4890cec5.sh

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/runner/.npm/_logs/2022-09-12T11_31_35_189Z-debug-0.log
Error: Process completed with exit code 1.

You will need to add @public to those too

pamapa avatar Sep 12 '22 11:09 pamapa

Nice work, thanks for taking care and thanks for your contribution!

pamapa avatar Sep 13 '22 12:09 pamapa

@pamapa can you pls publish a new version of the package with the changes?

rahul-sharma-uipath avatar Sep 14 '22 07:09 rahul-sharma-uipath

will do so

pamapa avatar Sep 14 '22 09:09 pamapa