[v5] plainCookie sets encrypted cookie #1550
-
Hi everyone, Here's my login handler: public async login({ auth, request, response }: HttpContextContract) {
const email = request.input("email");
const password = request.input("password");
const token = await auth.use("api").attempt(email, password);
response.plainCookie("authorization", `Bearer ${token.token}`, {
sameSite: "lax",
httpOnly: false,
secure: false,
});
return token.toJSON();
} This is the set-cookie header on the response according to DevTools:
The cookie seems to be encrypted, even though I used the plainCookie method. Am I doing something wrong, or is this how plainCookie works? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey. The cookie is not encrypted, just base64 encoded to avoid encoding issues, since with AdonisJS you can pass any datatype (Arrays, Objects) to cookies. So it is required to base64 encode them. Just run the following code to get the cookie value. JSON.parse(window.atob('eyJtZXNzYWdlIjoiQmVhcmVyIE16RS50SkhfY3RadTJ4VVNGeFlYNWlsOVVLNTN0Y2ZxeHF5OERnRUpIYW5SR05MUXdKWjJhTDhMU2dUVmdwQTAifQ')) |
Beta Was this translation helpful? Give feedback.
Hey. The cookie is not encrypted, just base64 encoded to avoid encoding issues, since with AdonisJS you can pass any datatype (Arrays, Objects) to cookies. So it is required to base64 encode them.
Just run the following code to get the cookie value.