Closed gitawego closed 8 months ago
Hi @gitawego , Thank you for your issue. Which version of the library are you using ? Do you have a sample (ofuscated) of your configuration ?
I'am searching from a long time why storage can be null. It never set to null in the code and values are required to refresh tokens correctly.
I put null
is only to make JSON.parse works, because undefined can't be parsed.
in this line of code: https://github.com/AxaFrance/oidc-client/blob/main/packages/oidc-client/src/initSession.ts#L66
const dataString = storage[`oidc.login.${configurationName}`];
dataString
could be undefined
,
and when parsed at line 68: https://github.com/AxaFrance/oidc-client/blob/main/packages/oidc-client/src/initSession.ts#L68
getLoginParamsCache[configurationName] = JSON.parse(dataString);
if dataString
is undefined, it throws error, because JSON.parse
can't parse undefined.
JSON.parse(JSON.stringify(undefined)) // throw Uncaught SyntaxError: "undefined" is not valid JSON
JSON.parse(undefined) //Uncaught SyntaxError: "undefined" is not valid JSON
JSON.parse(null) // return value null
JSON.parse(JSON.stringify(null)) // return value null
in my company, it's v7.6.0, but I compared, this part of the code is never changed.
I will manage this case with a warning instead of a crash. It would not be a problem for 90% of configurations cases.
But i Wonder how storage[oidc.login.${configurationName}
] can be null because it is set during authentication.
Hi @gitawego,
Do you have a sample of the stack trace of the error ?
I'll try to get it Monday.
after investigated the code, it's caused by a custom wrapper component which forces to do a code/authorization_code exchange without authorization, sorry for the confusion.
but I think your PR is still worthy to avoid breaking the application.
@gitawego, hello! What was the reason?
I have same problem
Same issue with Next application
Issue and Steps to Reproduce
when calling method
getLoginParams
in fileinitSession.ts
, if there is no param set in localStorage, then it throws errorIt happens very frequently.
based on the code,
JSON.parse
can't parse theundefined
value, ifdataString
is undefined, then oidc can't initialize the session.maybe we should add a default value to dataString, like
Versions
all