-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError with CacheLocation #95
Comments
Could you share your |
version 3.4.5
|
I am also facing same issue, can you help me how can i resolve cacheLocaation error const config = { const authenticationParameters = { export default class App extends Component { loginCallback(){ } } } render() {
} |
this works. i think this is because type widening, the cacheLocation key "localStorage" is widenened to type string so you need to force the cast to be of CacheLocation. I'm no expert though! |
After a bit of investigation, it seems all the types involved are defined on I think at the least it's fair to update the documentation since there's clearly an issue being experienced. This should be a good first issue to fix unless someone can submit a fix for it I will see if I can find some time in the next few weeks. I'll be out of town frequently though so it will be delayed. |
I included the changes to the documentation described in this issue with my latest PR (#107) since I was editing the docs anyway. This isn't a resolution, but hopefully, it will help others who are implementing this component for the first time. |
Hi @AndrewCraswell , this definitely seems like type widening to me, as this also works for me:
https://mariusschulz.com/blog/literal-type-widening-in-typescript this also works for me
as described here |
the documentation looks good to me, but i suppose you could take your pick from these alternative syntaxes as well. personally i don't think i see any clarity benefits of one over another. |
that also works for me, so i suppose you could export this enum for usage, this definitely has a clarity benefit, but then you need to redefine this on top of msal's definition. i think ideally the msal author might add this. |
Yeah, I'm just hesitant to redefine the |
seems like at some point this will make it through to msal |
Merged to dev today, we are releasing a patch sometime soon, the release should have this fix. We appreciate the contribution @jodonnell, Thankyou. |
Awesome, thank you.
… On Jul 23, 2019, at 11:34 AM, Sameera Gajjarapu ***@***.***> wrote:
Merged to dev today, we are releasing a patch sometime soon, the release should have this fix. We appreciate the contribution @jodonnell, Thankyou.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Thanks for pushing this through, @jodonnell. I've updated my PR #107 which was already updating the |
Ugh, sorry @AndrewCraswell, but the change got reverted. AzureAD/microsoft-authentication-library-for-js#851 |
Yeah. we have issues with TS projects with this change. If you have a different approach, feel free to push a new PR or one of us will get to this soon. |
I'm just using the msal library in react and I am getting the same error for session storage. How can I define the storage as a type or an enum in javascript, or do I just store it as an object? const msalConfig = { |
@scottyh527 You'd probably be better off raising with the MSAL library, as they're determining how to prioritize this fix. But to get you unblocked, have you tried @jodonnell's solution referenced above? enum CacheStorage {
LocalStorage = "localStorage",
SessionStorage = "sessionStorage"
}
// ...
const config = {
auth: {
authority: (process.env.REACT_APP_AUTHORITY as string),
clientId: (process.env.REACT_APP_AAD_APP_CLIENT_ID as string),
},
cache: {
cacheLocation: CacheStorage.LocalStorage,
storeAuthStateInCookie: true,
},
}; |
I tried his fix for adding the enum. I put this before the msalconfig object i created. enum CacheStorage { But it seems javascript doesn't allow for the enum. |
@scottyh527 this error is specific to typescript, if you aren't using typescript then you aren't getting the same error. what are you seeing exactly? |
assuming your are using typescript though you can try this forces the type of the string to be the string "localStorage" and not ANY string. |
@scottyh527 Oh sorry, didn't catch that you aren't using TypeScript. There should be several ways to do this, my preferred is: let CacheLocation = Object.freeze({
SessionStorage: 'sessionStorage',
LocalSotarge: 'localStorage'
}); Now you can use it as something closer to an Enum. |
I'm using react, not typescript. The error is ClientConfigurationError: The cache location provided is not valid. Provided value: sessionStorage. Possible values are: localStorage, sessionStorage. |
I'll give it a try thanks. Its hard for me to recreate it since a colleague caught it and I hadn't seen it until now. |
@AndrewCraswell i suspect what scotty and #104 are talking about is a different issue seems to stem from the msal lib which actually defines a javascript error |
i dug into their code a bit
reading the code i see
we need a bug for https://github.com/AzureAD/microsoft-authentication-library-for-js repo |
@jodonnell Any way I can get around that? My colleague was just using chrome not sure how it didn't support local or session storage. |
Having the same React / Not TypeScript issue out of the box when defining |
@mledwards I'm having the same problem (with JS not TS) within an iframe. I've tried localStorage and sessionStorage with a Popup. Any ideas? |
@andrewfabrizi My issue was that I'm using next.js which has server side rendering, so when Azure brings me back to the callback the server side is firing which doesn't have access to the browser's local storage. I haven't done it yet, but my work around will be to make the callback page simply trigger next link click to a client side page. Not sure if this helps your problem, but may help others. |
@mledwards it is strictly a static client-side website and I'm only having an issue when the page is rendered within an iframe. |
Hey, I am using this in React Native and getting same error please suggest some solution for React Native export const msalApp = new UserAgentApplication({ }); |
Another way to resolve this is to add the config type as import { Configuration } from 'msal';
const signInConfig: Configuration = {
auth: {
authority: signInAuthority,
clientId: applicationID,
redirectUri: reactRedirectUri,
validateAuthority: false
},
cache: {
cacheLocation: "localStorage",
storeAuthStateInCookie: true
}
}; |
If anyone has had the same issue as I did above while doing this via next.js SSR, I moved all of my code into a useEffect hook, which only runs client side, and that solved my problem 👍 Server side rendering doesn't have access to the browser / local caches. |
Describe the bug
I followed the documentation,
const config = {
auth: {
authority: (process.env.REACT_APP_AUTHORITY as string),
clientId: (process.env.REACT_APP_AAD_APP_CLIENT_ID as string),
},
cache: {
cacheLocation: "localStorage",
storeAuthStateInCookie: true
},
};
and got a TypeError
Argument of type '{ auth: { authority: string; clientId: string; }; cache: { cacheLocation: string; storeAuthStateInCookie: boolean; }; }' is not assignable to parameter of type 'Configuration'.
Types of property 'cache' are incompatible.
Type '{ cacheLocation: string; storeAuthStateInCookie: boolean; }' is not assignable to type 'CacheOptions'.
Types of property 'cacheLocation' are incompatible.
Type 'string' is not assignable to type '"sessionStorage" | "localStorage" | undefined'. [2345]
I fixed it by import CacheLocation and casting my string
cacheLocation: ("localStorage" as CacheLocation),
The text was updated successfully, but these errors were encountered: