jdx / mean-sample

Sample project for Write Modern Web Apps with the MEAN Stack by Jeff Dickey
https://mean-sample.herokuapp.com
166 stars 90 forks source link

jwt starts and ends with double quotes before encoding #10

Open nivaruofficial opened 9 years ago

nivaruofficial commented 9 years ago

Hi, i've fixed the issue of double quoting with the following code:

var auth = req.headers['x-auth']; auth = auth.replace(/"([^"]+(?="))"/g, '$1'); auth = jwt.decode(auth, config.secret);

I wonder why it happens!

shk33 commented 9 years ago

The problem is in Express response, it returns a json version of the jwt token Go to your session controller in the post action and inside the bcrypt.compare() callback find and remove this line

res.json(token);

And put this one instead

res.send(token);

This way the jwt token won't have double quoting.