AWS auth Cookie storage is not encoding the plus(+) character

66 Views Asked by At

I have the below code

const config = awsconfig;
config.cookieStorage = { domain: "mydomain", path: "/", expires: 365, sameSite: "lax", secure: true };

For example, if the email id [email protected], is getting stored as expected. ie : CognitoIdentityServiceProvider.727vitcmg8qrnffc3lmrnb9.arunk%40gmail.com.accessToken

But for the mail id [email protected]

CognitoIdentityServiceProvider.727vitcmg8qrnffc3lmrnb9.arunk+1%40gmail.com.accessToken

But the expected should be

CognitoIdentityServiceProvider.727vitcmg8qrnffc3lmrnb9.arunk%2B1%40gmail.com.accessToken

So the + character is not is getting encoded. Since I am using ngx-cookie-service in my angular project, this cookie is not getting deleted.

1

There are 1 best solutions below

1
Nikhil Makwana On

The + character is properly encoded in your cookie value; you can manually encode it before storing it in the cookie. You can use the JavaScript encodeURIComponent() function to achieve this:

const config = awsconfig;
const email = "[email protected]"; // Replace with your actual email address
const encodedEmail = encodeURIComponent(email);
config.cookieStorage = { domain: "mydomain", path: "/", expires: 365, sameSite: "lax", secure: true };

// Now, use the encoded email when setting the cookie value
const cookieValue = `CognitoIdentityServiceProvider.727vitcmg8qrnffc3lmrnb9.${encodedEmail}.accessToken`;