-
Notifications
You must be signed in to change notification settings - Fork 23
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
Advice | Accessing a JWT Claim #25
Comments
Change line 60 to |
function isObject(obj: unknown): obj is object {
return (
obj !== null && typeof obj === "object" && Array.isArray(obj) === false
);
}
function has<K extends string>(
key: K,
x: object
): x is { [key in K]: unknown } {
return key in x;
}
if(isObject(jwtpayload) && has("email", jwtpayload)) console.log(jwtpayload.email) Does this work? |
@timonson that works perfectly! Thank you for being so helpful. Could the djwt library be improved to help others who might run into this use case? Is the approach you suggested here normal? Just curious to hear your thoughts on this. Thank you again. |
@PaulFish-Radius the issue is that the payload of a JWS might be any value because the specification says:
Therefore checking if properties actually exist seems to be the right way. But I am open for better solutions of course. Maybe it helps that the two functions |
@timonson thank you for the addition - its great! |
I added some information to the README.md eaeecdc . |
Just for your information: My suggestions in this issue are deprecated now. The function |
Noob here - what's the best way to access claims on a JWT once validation has passed?
The text was updated successfully, but these errors were encountered: