registerOAuthInfos before Map creation
gavinr opened this issue · comments
Gavin Rehkemper commented
I'd like the ability to create an OAuthInfo
instance and pass it to IdentityManager
via a call to registerOAuthInfos([])
before I use useWebMap()
. This is currently impossible to do because I'd need to load the esri/identity/OAuthInfo
and esri/identity/IdentityManager
modules via loadModules
which then puts my hook call within a callback which is not allowed (from React error: Error: Invalid hook call. Hooks can only be called inside of the body of a function component
):
loadModules([
'esri/identity/OAuthInfo',
'esri/identity/IdentityManager',
]).then(function([OAuthInfo, esriId]) {
// https://developers.arcgis.com/javascript/latest/sample-code/identity-oauth-basic/index.html
var info = new OAuthInfo({
appId: 'xyz123',
popup: false,
});
esriId.registerOAuthInfos([info]);
const [ref, view] = useWebMap('aaaaaaaaaaaaaaaaaaaaaaaaa');
});
Potential Solutions
- Additional option to the existing hooks (ex:
useWebMap('aaaaaaaaaaaaaaaaaaaaaaaaa', { oAuthInfos })
- add a new hook (ex:
useIdentityManager()
) as part of this repo
Other Discussion
new hook vs introducing new options prior discussion: #6 (comment)