Skip to content

Commit

Permalink
convert id to url safe
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntVal committed Aug 9, 2024
1 parent e6ea5bf commit 68f328f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion apps/demo-app/src/app/webauthn/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ function getHumanReadablePubkey(pubkey: Uint8Array | undefined) {
return pubBase64;
}

function convertToUrlSafeBase64(base64: string) {
// Replace '+' with '-'
let urlSafeBase64 = base64.replace(/\+/g, "-");
// Replace '/' with '_'
urlSafeBase64 = urlSafeBase64.replace(/\//g, "_");
// Remove any '=' padding
urlSafeBase64 = urlSafeBase64.replace(/=+$/, "");
return urlSafeBase64;
}

export default function Page(): JSX.Element {
const [isConnected, setIsConnected] = useState(false);
const [loginAuthenticator, setLoginAuthenticator] = useState("");
Expand Down Expand Up @@ -165,7 +175,7 @@ export default function Page(): JSX.Element {
}

console.log(credential);
setLoginAuthenticator(credential.id);
setLoginAuthenticator(convertToUrlSafeBase64(credential.id));
setIsConnected(true);
} catch (error) {
console.log(error);
Expand Down

0 comments on commit 68f328f

Please sign in to comment.