Express JWT error: Not enough or too many segments in socket.io initial auth
During the initial handshake in which the token and username are passed, I catch this strange error -
{ handle: 10,
type: 'error',
className: 'Error',
constructorFunction: { ref: 11 },
protoObject: { ref: 12 },
prototypeObject: { ref: 3 },
properties:
[ { name: 'stack',
attributes: 2,
propertyType: 3,
ref: 3 },
{ name: 'arguments',
attributes: 2,
propertyType: 1,
ref: 3 },
{ name: 'type',
attributes: 2,
propertyType: 1,
ref: 3 },
{ name: 'message',
attributes: 2,
propertyType: 1,
ref: 13 } ],
text: 'Error: Not enough or too many segments' }
wrong JWT? is the initial token malformed?
+3
source to share
4 answers
As far as I know, this error was the result of an uncaught exception when parsing a JWT that refers to a user no longer in the db - the more common scenario is when the bcrypt comparison or whatever you use finds the hash comparison to be false - this is what I assumed in attention - not find a user I didn't. When I explained this, the error was gone.
+6
source to share
This happened to me in my angular app when I passed a messed up callback to my "then" statement.
// in my Auth Service
this.register = function (email, password) {
return $http.post(API_URL + 'register', {
email: email,
password: password
}).then(authSuccessful)
.catch(authError);
};
function authSuccessful(res) {
alert('success', 'Joy!', 'Welcome, ' + res.data.user.email + '.');
// authToken.setToken just puts the token in local storage.
authToken.setToken(res.token); // <- WRONG!!
$state.go("connections");
}
Should be:
function authSuccessful(res) {
alert('success', 'Joy!', 'Welcome, ' + res.data.user.email + '.');
authToken.setToken(res.data.token); // <- Yay!
$state.go("connections");
}
0
source to share