Skip to content

Commit

Permalink
convert from url safe to standard base64
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntVal committed Aug 9, 2024
1 parent 68f328f commit ec6cd33
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions apps/demo-app/src/app/webauthn/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,13 @@ 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;
function convertToStandardBase64(urlSafeBase64) {
let base64 = urlSafeBase64.replace(/-/g, "+");
base64 = base64.replace(/_/g, "/");
while (base64.length % 4 !== 0) {
base64 += "=";
}
return base64;
}

export default function Page(): JSX.Element {
Expand Down Expand Up @@ -175,7 +174,7 @@ export default function Page(): JSX.Element {
}

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

0 comments on commit ec6cd33

Please sign in to comment.