-
Notifications
You must be signed in to change notification settings - Fork 994
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
chore(api): Typescript work and minor fixes #1382
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8ae4445
chore(auth, ts): parseJWT remove wrong types
Krisztiaan 98b3225
chore(auth): remove redundancy, add null fallbacks
Krisztiaan 905877a
chore(auth, ts): slightly safer typing for graphql
Krisztiaan 4943cad
Merge branch 'main' into ts/auth
Krisztiaan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,36 @@ | ||
const appMetadata = (token: { | ||
decoded: { [index: string]: Record<string, unknown> } | ||
type MetaDataBase = { roles?: string[]; authorization?: { roles?: string[] } } | ||
|
||
function appMetadata(token: { | ||
decoded: { [index: string]: any } | ||
namespace?: string | ||
}): any => { | ||
}): MetaDataBase { | ||
const claim = token.namespace | ||
? `${token.namespace}/app_metadata` | ||
: 'app_metadata' | ||
return token.decoded?.[claim] || {} | ||
} | ||
|
||
const roles = (token: { | ||
decoded: { [index: string]: Record<string, unknown> } | ||
namespace?: string | ||
}): any => { | ||
const metadata = appMetadata(token) | ||
function roles( | ||
token: { | ||
decoded: { [index: string]: any } | ||
}, | ||
metadata: MetaDataBase | ||
): string[] { | ||
return ( | ||
token.decoded?.roles || | ||
((token.decoded?.roles as unknown) as string[]) || | ||
metadata?.roles || | ||
metadata.authorization?.roles || | ||
[] | ||
) | ||
} | ||
|
||
export const parseJWT = (token: { | ||
decoded: { [index: string]: Record<string, unknown> } | ||
export function parseJWT(token: { | ||
decoded: { [index: string]: any } | ||
namespace?: string | ||
}): any => { | ||
}) { | ||
const appMetaData = appMetadata(token) | ||
return { | ||
appMetadata: appMetadata(token), | ||
roles: roles(token), | ||
appMetadata: appMetaData, | ||
roles: roles(token, appMetaData), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious, why is "../" preferred over "src"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1381 it'll be addressed there, if fixable.