使用nodejs api在figma desktop中存储cookie



我正在使用typescript创建一个figma插件。我在插件中创建一个登录模块。我用nodejs创建了API。我面临的问题是我的cookie没有被存储。

我已经打开了figma桌面应用程序的控制台,但是没有cookie。

我们可以用nodejs创建cookie并将其存储在桌面应用程序中吗?

Code for Nodejs:
app.post("/user-login", async(req,res)=>{
const {email, password} = req.body;
db.query(`select * from users where email = '${email}' and role_id='3'`, async(err,result)=>{
if(err){
res.json({status: false,msg:"There was an error while fetching data. Please Try again later"});
}else{
// console.log(result);
if(result.length > 0){
var resp = await bcrypt.compare(password, result[0].password);
if(resp){
const regtoken = jwt.sign({ id: result[0].user_id }, "943h9DH(H#R(*#HD(HD(RTH#(*Dh9th9gn498cNA(RN97BR()))))))d@ERR#R%", {
expiresIn: "90d",
// httpOnly: true
})
const cookiesOptions = {
expiresIn: new Date(Date.now() + "" * 24 * 60 * 60 * 1000),
// httpOnly: true
}
res.cookie('checklogin', regtoken, cookiesOptions);
res.json({status: true,msg:"Login successfully"});
}else{
res.json({status: false,msg:"Invalid login credentials"});
}
}else{
res.json({status: false,msg:"Access Denied"});
}
}
})
})

击中api的代码:

const PostData = async(e) => {
e.preventDefault();
var formdata =  new FormData();
formdata.append('email', user.email);
formdata.append('password', user.password);
var data = JSON.stringify({email:user.email, password:user.password})

const res = await axios.post("http://localhost:8000/user-login",data, {
headers: {
"Content-Type" : "application/json",
"Access-Control-Allow-Origin": "*"
}
})
if(res.data.status){
setCookie('testing', 'true')
// localStorage.setItem("islogin","true");
console.log("login done");
}else{
console.log("login failed");
}
}

问题是cookie存储在浏览器中,而不是桌面应用程序中。

负责创建和传输cookie到客户端的Node.js服务器没有将其存储在Figma桌面应用程序中,因为它是一个非常规的存储cookie的地方-它们通常由web浏览器保存,而不是桌面应用程序。

要在桌面应用程序中保留数据,您可以考虑多种选择,例如根据应用程序的规格使用数据库,本地存储甚至用户的系统文件。