-
Notifications
You must be signed in to change notification settings - Fork 337
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
add reserved claims types #107
Conversation
We're having a bit of a discussion about whether to return I would like to keep these types as flexible as possible. Would the generic approach where you can do the following also work for you? type JwtPayload = {
iat: number;
exp: number;
...
roles: string[];
};
const { username } = jwt_decode<JwtPayload>(token); |
@Sambego that would work but I'd be curious why use unknown if the RFC defines reserved optional claims? Users could then extend the type interface if they have custom claims that they want to add. |
You can combine both approaches, generics with default value. export interface JwtClaims {
iss?: string;
sub?: string;
aud?: string[] | string;
exp?: number;
nbf?: number;
iat?: number;
jti?: string;
}
export default function jwtDecode<T = JwtClaims>(token: string, options?: JwtDecodeOptions): T;
// or using extention
export default function jwtDecode<T extends JwtClaims = JwtClaims>(token: string, options?: JwtDecodeOptions): T; This way, you can pass from the outside your type but by default it will be |
Co-authored-by: Gabriel de Carvalho Vaz <gabrielcvaz@outlook.com>
Thanks, everybody for chiming in on this, your insights are appreciated 💪
|
These updates are available in |
By submitting a PR to this repository, you agree to the terms within the Auth0 Code of Conduct. Please see the contributing guidelines for how to create and submit a high-quality PR for this repo.
Description
Add type definitions for reserved claims as listed in section 4.1 of the RFC.
Checklist
master