Add JWT to login forms

This commit is contained in:
Dane Everitt 2018-05-28 12:48:42 -07:00
parent 47c1ecc9bc
commit ad69193ac0
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
8 changed files with 93 additions and 6 deletions

View file

@ -0,0 +1,33 @@
import JwtDecode from 'jwt-decode';
const User = function () {
this.id = 0;
this.admin = false;
this.email = '';
};
/**
* Return a new instance of the user model using a JWT.
*
* @param {string} token
* @returns {User}
*/
User.prototype.fromJwt = function (token) {
return this.newModel(JwtDecode(token));
};
/**
* Return an instance of this user model with the properties set on it.
*
* @param {object} obj
* @returns {User}
*/
User.prototype.newModel = function (obj) {
this.id = obj.id;
this.admin = obj.admin;
this.email = obj.email;
return this;
};
export default User;