Closed joseramongravity closed 5 years ago
Can you give an example of the code you're using? You need to explicitly set footers to none
if using callbacks, so that's my initial suspicion as to the cause.
const signToken = async(input) => {
const message = input
const raw = Buffer.from('secret', 'hex')
let sk = new Paseto.PrivateKey(new Paseto.V2()) // Make a new key with the App Secret
await sk.inject(raw)
const encoder = sk.protocol()
const token = await encoder.encrypt(message, sk, null,(err, token) => {
if (err) { return cb(err)}
return token
}) // Encrypt message
return token
}
Its like this i think i dont have footers
I'm unclear. Why are you using both async/await and callbacks? You should be able to just use await encode.encrypt(...)
as described here: https://github.com/sjudson/paseto.js#callbacks-promises-and-asyncawait
The cb
in if (err) { return cb(err)}
is not defined in that snippet.
I have tried the three different ways, but that one used to work like one week ago.
But the other methods give me this error:
Failed to construct 'TextDecoder': the 'fatal' option is unsupported.
This method gives me the cb error:
const signToken = (input) => {
const message = input
const raw = Buffer.from('secret', 'hex')
let sk = new Paseto.PrivateKey(new Paseto.V2()) // Make a new key with the App Secret
sk.inject(raw)
const encoder = sk.protocol()
const token = encoder.encrypt(message, sk, null,(err, token) => {
if (err) { return cb(err)}
return token
}) // Encrypt message
return token
}
This one the Text Decoder
const signToken = (input) => {
const message = input
const raw = Buffer.from('secret', 'hex')
let sk = new Paseto.PrivateKey(new Paseto.V2()) // Make a new key with the App Secret
sk.inject(raw)
const encoder = sk.protocol()
const token = encoder.encrypt(message, sk).then(token => {
console.log(token)
})
return token
}
This one also gives me the Text Decoder error
const signToken = async(input) => {
const message = input
const raw = Buffer.from('secret', 'hex')
let sk = new Paseto.PrivateKey(new Paseto.V2()) // Make a new key with the App Secret
await sk.inject(raw)
const encoder = await sk.protocol()
const token = await encoder.encrypt(message, sk)
console.log('token')
return token
}
TextDecoder
isn't part of this library. Additionally, for
const raw = Buffer.from('secret', 'hex')
'secret' isn't valid hex. When I try and run this last example, I get an invalid key length error...
Okay i will check the TextDecoder
btw i dont have secret
as the key i just placed it there as an example it is not the real key
Thanks
I'll close for now, you're welcome to reopen if you can provide a reproducible example.
Error happens on macOs when trying to generate the token
Edit: This happens when i try to use something that is not the callback function
Error: Failed to construct 'TextDecoder': the 'fatal' option is unsupported.