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

Update public_types.ts #5395

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Update public_types.ts #5395

wants to merge 1 commit into from

Conversation

au5ton
Copy link

@au5ton au5ton commented Aug 27, 2021

According to RFC7519:

Claim Value
The value portion of a claim representation. A Claim Value can be
any JSON value.

I thought it might make more sense to include some additional JSON primitives. This would make checking claims like { admin: true } more type safe.


In my specific use case, I am using this function from Reactfire:

// pass in an object describing the custom claims a user must have
const {status, data: signInCheckResult} = useSignInCheck({requiredClaims: {admin: true}});

From: https://github.com/FirebaseExtended/reactfire/blob/a2d2f1c36450515e81e07bd50f539266f5d825dc/docs/reference/modules/auth.md#usesignincheck

Which types the requiredClaims option to the types affected by this pull request:

import type { Auth, User, IdTokenResult } from 'firebase/auth';
type Claims = IdTokenResult['claims'];

From: https://github.com/FirebaseExtended/reactfire/blob/2b564029a1903ef6b3f16c555693c264982ae678/src/auth.tsx#L8-L9

Without these changes, the useSignInCheck code block from above would produce the following type error:

Type 'boolean' is not assignable to type 'string | object'.ts(2322)
auth-public.d.ts(2040, 5): The expected type comes from this index signature.

This could be a seen as a Reactfire issue, but unless I'm mistaken, I don't see the harm in adding these primitives to the custom claims type.

@changeset-bot
Copy link

changeset-bot bot commented Aug 27, 2021

⚠️ No Changeset found

Latest commit: 56779f3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@google-cla
Copy link

google-cla bot commented Aug 27, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@au5ton
Copy link
Author

au5ton commented Aug 27, 2021

@googlebot I signed it!

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.

2 participants