Add JWT to login forms
This commit is contained in:
parent
47c1ecc9bc
commit
ad69193ac0
8 changed files with 93 additions and 6 deletions
33
resources/assets/scripts/models/user.js
Normal file
33
resources/assets/scripts/models/user.js
Normal 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;
|
Loading…
Add table
Add a link
Reference in a new issue