Strip out JWT usage and use cookies to track the currently logged in user
This commit is contained in:
parent
a7fae86e58
commit
6336e5191f
9 changed files with 44 additions and 144 deletions
|
@ -1,40 +1,4 @@
|
|||
import isString from 'lodash/isString';
|
||||
import jwtDecode from 'jwt-decode';
|
||||
|
||||
export default class User {
|
||||
/**
|
||||
* Get a new user model from the JWT.
|
||||
*
|
||||
* @return {User | null}
|
||||
*/
|
||||
static fromToken(token) {
|
||||
if (!isString(token)) {
|
||||
token = this.getToken();
|
||||
}
|
||||
|
||||
if (!isString(token) || token.length < 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const data = jwtDecode(token);
|
||||
if (data.user) {
|
||||
return new User(data.user);
|
||||
}
|
||||
} catch (ex) {}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the JWT for the authenticated user.
|
||||
*
|
||||
* @returns {string | null}
|
||||
*/
|
||||
static getToken() {
|
||||
return localStorage.getItem('token');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user model.
|
||||
*
|
||||
|
@ -46,14 +10,14 @@ export default class User {
|
|||
* @param {String} language
|
||||
*/
|
||||
constructor({
|
||||
admin,
|
||||
root_admin,
|
||||
username,
|
||||
email,
|
||||
first_name,
|
||||
last_name,
|
||||
language,
|
||||
}) {
|
||||
this.admin = admin;
|
||||
this.admin = root_admin;
|
||||
this.username = username;
|
||||
this.email = email;
|
||||
this.name = `${first_name} ${last_name}`;
|
||||
|
@ -61,11 +25,4 @@ export default class User {
|
|||
this.last_name = last_name;
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the JWT belonging to the current user.
|
||||
*/
|
||||
getJWT() {
|
||||
return jwtDecode(User.getToken());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue