我将jsonwebtoken在我的 React 项目中创建一个表单数据的令牌。
import jwt from 'jsonwebtoken';
const MyForm = () => {
const submitForm = (e) => {
e.preventDefault();
const data = { name: 'name', email: 'email', subject: 'subject', message: 'message' };
const token = jwt.sign(data, 'qwerty');
console.log(token);
}
return(
<form onSubmit={submitForm}>
...
</form>
);
}
export default MyForm;
Run Code Online (Sandbox Code Playgroud)
发生以下错误。
TypeError: Right-hand side of 'instanceof' is not an object
push../node_modules/jsonwebtoken/sign.js.module.exports [as sign]
../node_modules/jsonwebtoken/sign.js:108
105 | return failure(new Error('secretOrPrivateKey must have a value'));
106 | }
107 | …Run Code Online (Sandbox Code Playgroud)