When sending an invalid token, the HTTP API from the Pusher now returns a 401 instead of an HTTP 500.
This commit is contained in:
parent
ff77a18262
commit
598c7412a2
2 changed files with 14 additions and 8 deletions
|
@ -116,11 +116,12 @@ export class Room {
|
||||||
this._contactPage = data.contactPage || CONTACT_URL;
|
this._contactPage = data.contactPage || CONTACT_URL;
|
||||||
return new MapDetail(data.mapUrl, data.textures);
|
return new MapDetail(data.mapUrl, data.textures);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error => getMapDetail", e, e.response);
|
if (axios.isAxiosError(e) && e.response?.status == 401 && e.response?.data === "Token decrypted error") {
|
||||||
//TODO fix me and manage Error class
|
console.warn("JWT token sent could not be decrypted. Maybe it expired?");
|
||||||
if (e.response?.data === "Token decrypted error") {
|
|
||||||
localUserStore.setAuthToken(null);
|
localUserStore.setAuthToken(null);
|
||||||
window.location.assign("/login");
|
window.location.assign("/login");
|
||||||
|
} else {
|
||||||
|
console.error("Error => getMapDetail", e, e.response);
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { isMapDetailsData, MapDetailsData } from "../Services/AdminApi/MapDetail
|
||||||
import { socketManager } from "../Services/SocketManager";
|
import { socketManager } from "../Services/SocketManager";
|
||||||
import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager";
|
import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager";
|
||||||
import { v4 } from "uuid";
|
import { v4 } from "uuid";
|
||||||
|
import { InvalidTokenError } from "./InvalidTokenError";
|
||||||
|
|
||||||
export class MapController extends BaseController {
|
export class MapController extends BaseController {
|
||||||
constructor(private App: TemplatedApp) {
|
constructor(private App: TemplatedApp) {
|
||||||
|
@ -85,11 +86,15 @@ export class MapController extends BaseController {
|
||||||
userId = authTokenData.identifier;
|
userId = authTokenData.identifier;
|
||||||
console.info("JWT expire, but decoded", userId);
|
console.info("JWT expire, but decoded", userId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (e instanceof InvalidTokenError) {
|
||||||
// The token was not good, redirect user on login page
|
// The token was not good, redirect user on login page
|
||||||
res.writeStatus("500");
|
res.writeStatus("401 Unauthorized");
|
||||||
res.writeHeader("Access-Control-Allow-Origin", FRONT_URL);
|
res.writeHeader("Access-Control-Allow-Origin", FRONT_URL);
|
||||||
res.end("Token decrypted error");
|
res.end("Token decrypted error");
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
return this.errorToResponse(e, res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue