Skip to content

Commit

Permalink
safer base64 handling in story
Browse files Browse the repository at this point in the history
  • Loading branch information
mickhansen committed May 29, 2024
1 parent a587f13 commit 4f3930d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/components/AuthMethodButton/AuthMethodButton.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,22 @@ export default {
}
} as ComponentMeta<typeof AuthMethodButton>;

function tryBase64Decode(input?: string) {
if (!input) return null;

try {
const decoded = atob(input);
if (btoa(decoded) === input) return decoded;
return null;
} catch (err) {
return null;
}
}


// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
const Template: ComponentStory<typeof AuthMethodButton> = (args, {globals}) => {
const loginHint =
(args as any).loginHint && btoa(atob((args as any).loginHint)) === (args as any).loginHint ? atob((args as any).loginHint) :
(args as any).loginHint;
const loginHint = tryBase64Decode((args as any).loginHint);

return (
<CriiptoVerifyProvider
Expand Down

0 comments on commit 4f3930d

Please sign in to comment.