Thanks for providing the code 😀 I’m not a developer and I asked ChatGPT to see if they can help give us some clues.
“Based on the code you provided, it seems that you are trying to extract a cookie value from the request headers and send it back as a JSON response. However, you are always getting a null value for the token. There could be a few reasons why this is happening. Here are some things you can try to debug the issue:
Check the cookie name: Make sure that the name of the cookie you are trying to extract matches the name of the cookie that is being sent in the request. In this case, you are trying to extract a cookie named “_ms-mid”. You can verify this by checking the “cookieString” variable in your console logs.
Check the format of the cookie string: The “cookieString” variable should contain a string in the format “cookieName=cookieValue”. Make sure that the cookie string is being parsed correctly by the “getCookie” function.
Check if the cookie is being sent in the request headers: Make sure that the cookie is being sent in the request headers by checking the “req.headers.cookie” value in your console logs.
Check if the cookie is being sent with the correct path and domain: Cookies can be set with specific paths and domains. Make sure that the cookie is being sent with the correct path and domain that matches the current request.
You can try these steps to debug the issue and find out why you are always getting a null value for the token.”
Josh Lopez Nicolas Scott If there’s anything you guys notice 😀
6 comments
Does this help?
https://docs.memberstack.com/hc/en-us/articles/7253255689755-Using-Permissions-and-Token-Verification-to-Secure-Your-Site#heading-3
You can ignore the permissions and just focus on the parts that mention the token.
yes it help but I always getting null Token values ? this is my code
if (parsedUrl.pathname === "/get-token") {
try {
console.log("req.headers:---->", req.headers);
console.log("req.headers.cookie:---->", req.headers.cookie);
// console.log("req.headers.get(cookie)----> ", req.headers.get("cookie"));
const cookieString =req.headers.cookie; // req.headers.get("cookie") ; //
console.log("cookieString:", cookieString);
const cookieName = "_ms-mid";
const token = getCookie(cookieString, cookieName);
console.log("Access Token:", token); res.setHeader("Content-Type", "application/json"); res.end(JSON.stringify({ token })); } catch (error) { console.error(error); res.statusCode = 401; res.end("Unauthorized"); }}
exemple of returned data :
Hello Khaoula 👋
Thanks for providing the code 😀 I’m not a developer and I asked ChatGPT to see if they can help give us some clues.
“Based on the code you provided, it seems that you are trying to extract a cookie value from the request headers and send it back as a JSON response. However, you are always getting a null value for the token.
There could be a few reasons why this is happening. Here are some things you can try to debug the issue:
You can try these steps to debug the issue and find out why you are always getting a null value for the token.”
Josh Lopez Nicolas Scott If there’s anything you guys notice 😀
Yes, I wrote this code. Token is probably null because of this line:
It looks like the getCookie function that was meant to go with this code is missing.
You'll need to replace getCookie() with the actual token verification method from the admin SDK and pass in the token.
Like below:
I'll update the docs. Apologies for the confusion!
Thanks Nicolas 🙏 We appreciate all the work you do!
Jayess Nicolas Scott thank you very much for your answer 🙏
Please sign in to leave a comment.