没有从JWT的有效载荷中获得所有的字段(not getting all the fields from payload of JWT)
我创建了一个MEAN堆栈web应用程序,它具有登录注销选项。用户登录后,我使用了jsonwebtoken npm软件包。 这里的主要问题是当用户登录一个JWT时被创建,并且该令牌的有效负载包含用户名,电子邮件和全名,但是在解码令牌时我只获取用户名和电子邮件字段
这里是jwt.sign函数 -
var token=jwt.sign({userid:user.username,email:user.email,fullname:user.fullname},secret,{expiresIn:'24h'});
这里jwt.verify方法 -
jwt.verify(token,secret,function(err,decoded){ if(err){ res.json({success:false,message:"invalid token"}); } else { req.decoded=decoded; next(); } })
令牌示例 -
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOiJuaXRpbi5zYWNoZGV2IiwiZW1haWwiOiJuaXRpbi5zYWNoZGV2QGVtYWlsLmNvbSIsImlhdCI6MTQ4NDU1ODAxMiwiZXhwIjoxNDg0NjQ0NDEyfQ.fWogT-aHJY4Xyc8Ebm4OXPkWD3poaWG3IAAf9VS-q58
令牌解码 -
{ "userid": "nitin.sachdev", "email": "nitin.sachdev@email.com", "iat": 1484558012, "exp": 1484644412 }
userSchema -
var UserSchema=new Schema({ fullname:String, username:{type:String,lowercase:true,required:true,unique:true}, password:{type:String,required:true}, email:{type:String,required:true,lowercase:true,unique:true}, contactno:Number, orgname:String });
i have created a MEAN stack web app which has login logout option.for user to be logged in i have used jsonwebtoken npm package. the main problem here is when user logs in a JWT is created and in that token's payload contain username,email and fullname but while decoding the token i am only getting username and email field
here is jwt.sign function-
var token=jwt.sign({userid:user.username,email:user.email,fullname:user.fullname},secret,{expiresIn:'24h'});
and here jwt.verify method-
jwt.verify(token,secret,function(err,decoded){ if(err){ res.json({success:false,message:"invalid token"}); } else { req.decoded=decoded; next(); } })
token example-
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOiJuaXRpbi5zYWNoZGV2IiwiZW1haWwiOiJuaXRpbi5zYWNoZGV2QGVtYWlsLmNvbSIsImlhdCI6MTQ4NDU1ODAxMiwiZXhwIjoxNDg0NjQ0NDEyfQ.fWogT-aHJY4Xyc8Ebm4OXPkWD3poaWG3IAAf9VS-q58
token decoded-
{ "userid": "nitin.sachdev", "email": "nitin.sachdev@email.com", "iat": 1484558012, "exp": 1484644412 }
userSchema -
var UserSchema=new Schema({ fullname:String, username:{type:String,lowercase:true,required:true,unique:true}, password:{type:String,required:true}, email:{type:String,required:true,lowercase:true,unique:true}, contactno:Number, orgname:String });
原文:https://stackoverflow.com/questions/41673114
最满意答案
在
--emscripten_dir
和Empscripten路径之间不应该有=
。 输出文件夹也应该是最后一个参数。 像这样尝试:python ./platforms/js/build_js.py --emscripten_dir /root/Downloads/emsdk-portable/emscripten/1.37.33 /root/Downloads/opencvjspackage
提示:确保
/root/Downloads/opencvjspackage
存在,并且是要将opencv.js
内置到的位置。 还要确保cmake
已安装。There should be no
=
between--emscripten_dir
and the Empscripten path. Also the output folder should be the last argument. Try like this:python ./platforms/js/build_js.py --emscripten_dir /root/Downloads/emsdk-portable/emscripten/1.37.33 /root/Downloads/opencvjspackage
Tip: make sure
/root/Downloads/opencvjspackage
exists and is where you wantopencv.js
to be built into. Also make surecmake
is installed.
相关问答
更多-
Windows上的PATH环境变量不需要引号。 set PATH=C:\Program Files (x86)\CMake\bin\;%PATH% Quotes aren't needed in PATH environmental variables on Windows. set PATH=C:\Program Files (x86)\CMake\bin\;%PATH%
-
使用BUILD_AS_WORKER标志进行编译。 emcc -std=c++11 worker.cpp -s EXPORTED_FUNCTIONS="['_one']" -s BUILD_AS_WORKER=1 -o worker.js Compile with BUILD_AS_WORKER flag. emcc -std=c++11 worker.cpp -s EXPORTED_FUNCTIONS="['_one']" -s BUILD_AS_WORKER=1 -o worker.js
-
Emscripten与模块加载器(Emscripten with module loaders)[2022-09-10]
emcc文档中有两个可以帮助的命令行选项, - --pre-js和--pre-js --post-js 。 它们允许您包装生成的代码,因此允许您与AMD集成。 例如,您可以使用前缀文件 // prefix.js define(function() { return function(Module) { 和后缀文件 // postfix.js }; }); 您将使用类似的东西编译输出到myModule.js emcc --pre-js prefix.js ... -
我对此感到沮丧,最终建立了一个完美编译的Ubuntu系统。 I got frustrated with this and ended up building a Ubuntu system which compiles things perfectly.
-
在--emscripten_dir和Empscripten路径之间不应该有= 。 输出文件夹也应该是最后一个参数。 像这样尝试: python ./platforms/js/build_js.py --emscripten_dir /root/Downloads/emsdk-portable/emscripten/1.37.33 /root/Downloads/opencvjspackage 提示:确保/root/Downloads/opencvjspackage存在,并且是要将opencv.js内置到的 ...
-
Emscripten 1.34.1问题(Emscripten 1.34.1 Issue)[2022-09-16]
这似乎是1.34.1中的回归。 我有完全相同的问题。 升级到1.34.6后,错误消失了。 我没有修改它,但我建议你也更新到1.34.6+。 This appear to be a regression in 1.34.1. I had the exact same issue. After upgrading to 1.34.6 the error went away. I don't which commit fixed it but I would suggest you also update to ... -
Emscripten没有SDL(Emscripten without SDL)[2023-12-19]
我建议你使用Cheerp - emscripten的替代品 - Cheerp有一个可用的WebGL演示,它也有更多连贯/更新的文档/示例 I suggest you use Cheerp - an alternative to emscripten - Cheerp has a working WebGL demo, it also has much more coherent/updated docs/examples -
麻烦与emscripten设置(Trouble with emscripten setup)[2022-04-22]
这看起来非常类似于此处报告的问题: https : //github.com/kripken/emscripten/issues/1432 This looks very similar to the issue reported here: https://github.com/kripken/emscripten/issues/1432 -
在cmake调用中指定编译器是不够的,您需要工具链。 为此,请使用emcmake cmake [options] 。 它将使用emscripten设置编译所需的一切。 Specifying the compiler in the cmake call is not enough, you need the toolchain. To do that, use emcmake cmake [options]. It will set everything you need to compile using e ...
-
preamble.js本身不能在浏览器中加载,但是当你使用emscripten生成一个JavaScript(或HTML)输出文件时(例如通过调用emcc foo.c -o foo.js ),它将包含一个预处理版本前导码以及输出文件中的asm.js代码。 (或者,如果您使用WebAssembly,它还将生成foo.wasm文件以与foo.js一起使用)。 输出foo.js文件应该可以在浏览器中加载(或者例如node.js,如果它不使用Web API)。 preamble.js by itself can't ...