Skip to content
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

Avoid using readonly for public exposed reactive properties #243

Merged
merged 2 commits into from
Jul 18, 2023

Conversation

frederikprijck
Copy link
Member

@frederikprijck frederikprijck commented Jul 14, 2023

Changes

Using readonly() kinda changes the types in such a way that it marks all properties as readonly. Instead of actual IdToken (or User) types, it's actualy using an inline type based on the IdToken (but marking everything as readonly).

This means that the Auth0VueClient interface defined properties such as IdTokenClaims as a Ref<IdToken | undefined>, the Auth0VuePlugin has them being inferred to as DeepReadonly<UnwrapNestedRefs<IdToken>>, which doesn't always align.

This can become complicated to type properly, while they don't really need to be marked as read-only.

Dropping the read-only shouldn't cause issues, as they share the same public API:

const x = ref<IdToken>({__raw: 'abc'});
const xReadOnly = readonly(x);

console.log('raw', { x, xReadOnly }); // Logs x: RefImpl and xReadOnly: Proxy(RefImpl)
console.log('value', { x: x.value, xReadOnly: xReadOnly?.value }); // Logs 2x Proxy(Object)
console.log('property', { x: x.value.__raw, xReadOnly: xReadOnly?.value.__raw }); // Logs 2x 'abc'

With our SDK, the above would be:

console.log(auth0.idTokenClaims); // Logs RefImpl after this PR, Proxy(RefImpl) before this PR.
console.log(auth0.idTokenClaims.value); // Logs Proxy(Object) before and after this PR.
console.log(auth0.idTokenClaims.value.name); // Logs the correct claim value before and after this PR

As you can see, this should not change anything in how users can interact with our public reactive API.

References

Closes #240

Checklist

@jonasingvar
Copy link

I was having this issue with the readonly properties (build would fail) and have confirmed it's working now with this fix. Thank you

@frederikprijck frederikprijck merged commit 25dc3c0 into main Jul 18, 2023
@frederikprijck frederikprijck deleted the fix/240 branch July 18, 2023 08:44
@frederikprijck frederikprijck mentioned this pull request Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v2.2.1] Auth0Plugin is incompatible with Auth0VueClient (exactOptionalPropertyTypes: true)
4 participants