Skip to content

Commit

Permalink
fix: sign interface for cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
Bekacru committed Dec 10, 2024
1 parent 7634b82 commit c975946
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ utilities provided by `@better-auth/utils`:
|-------------------|----------------------------------------------------|
| [**Digest**](#digest) | Hash inputs using sha family hash functions. |
| [**HMAC**](#hmac) | Hash inputs using HMAC with a secret key. |
| [**Random String**](#random-string) | Generate random strings with a specified length and charset. |
| [**Random**](#random-string) | Generate random strings with a specified length and charset. |
| [**RSA**](#rsa) | Perform encryption, decryption, signing, and verification with RSA keys. |
| [**ECDSA**](#ecdsa) | Perform signing and verification with ECDSA keys. |
| [**Base64**](#base64) | Encode and decode data in base64 format. |
Expand Down
10 changes: 6 additions & 4 deletions src/cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,15 @@ export const cookies = {
const { name, value, attributes } = input;
const opt = { ...attributes };
const signature = input.signed
? await hmac.sign(input.signed.key, value)
? await hmac.sign(input.signed.key, {
data: value,
})
: undefined;
const base64Signature = signature
? await base64.encode(signature, {
urlSafe: true,
padding: false,
})
urlSafe: true,
padding: false,
})
: undefined;
const _value = base64Signature ? `${value}.${base64Signature}` : value;
let cookie = `${name}=${encodeURIComponent(_value)}`;
Expand Down

0 comments on commit c975946

Please sign in to comment.