Verify user in admin
- If 404, user don't exist in admin, it will be anonym user - if 403, user is ban or not associate in the world
This commit is contained in:
parent
bf9dfcc835
commit
dfa6d2cc66
@ -62,6 +62,17 @@ class AdminApi {
|
|||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fetchCheckUserByToken(organizationMemberToken: string): Promise<AdminApiData> {
|
||||||
|
if (!ADMIN_API_URL) {
|
||||||
|
return Promise.reject('No admin backoffice set!');
|
||||||
|
}
|
||||||
|
//todo: this call can fail if the corresponding world is not activated or if the token is invalid. Handle that case.
|
||||||
|
const res = await Axios.get(ADMIN_API_URL+'/api/check-user/'+organizationMemberToken,
|
||||||
|
{ headers: {"Authorization" : `${ADMIN_API_TOKEN}`} }
|
||||||
|
)
|
||||||
|
return res.data;
|
||||||
|
}
|
||||||
|
|
||||||
reportPlayer(reportedUserUuid: string, reportedUserComment: string, reporterUserUuid: string) {
|
reportPlayer(reportedUserUuid: string, reportedUserComment: string, reporterUserUuid: string) {
|
||||||
return Axios.post(`${ADMIN_API_URL}/api/report`, {
|
return Axios.post(`${ADMIN_API_URL}/api/report`, {
|
||||||
reportedUserUuid,
|
reportedUserUuid,
|
||||||
|
@ -2,6 +2,7 @@ import {ALLOW_ARTILLERY, SECRET_KEY} from "../Enum/EnvironmentVariable";
|
|||||||
import {uuid} from "uuidv4";
|
import {uuid} from "uuidv4";
|
||||||
import Jwt from "jsonwebtoken";
|
import Jwt from "jsonwebtoken";
|
||||||
import {TokenInterface} from "../Controller/AuthenticateController";
|
import {TokenInterface} from "../Controller/AuthenticateController";
|
||||||
|
import {adminApi, AdminApiData} from "../Services/AdminApi";
|
||||||
|
|
||||||
class JWTTokenManager {
|
class JWTTokenManager {
|
||||||
|
|
||||||
@ -41,12 +42,22 @@ class JWTTokenManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//verify token
|
||||||
if (!this.isValidToken(tokenInterface)) {
|
if (!this.isValidToken(tokenInterface)) {
|
||||||
reject(new Error('Authentication error, invalid token structure.'));
|
reject(new Error('Authentication error, invalid token structure.'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//verify user in admin
|
||||||
|
return adminApi.fetchCheckUserByToken(tokenInterface.userUuid).then(() => {
|
||||||
resolve(tokenInterface.userUuid);
|
resolve(tokenInterface.userUuid);
|
||||||
|
}).catch((err) => {
|
||||||
|
//anonymous user
|
||||||
|
if(err.response && err.response.status && err.response.status === 404){
|
||||||
|
return resolve(tokenInterface.userUuid);
|
||||||
|
}
|
||||||
|
reject(new Error('Authentication error, invalid token structure. ' + err));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user