Skip to content

Commit

Permalink
catch errors in auth (#240)
Browse files Browse the repository at this point in the history
* catch errors in auth

* Fix code formatting

---------

Co-authored-by: Format Bot <[email protected]>
  • Loading branch information
dragazo and Format Bot authored May 10, 2024
1 parent 9972db2 commit be2dcb2
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/procedures/utils/router-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const cookieParser = require("cookie-parser");
const bodyParser = require("body-parser");
const cloud = require("../../cloud-client");
const axios = require("axios");
const logger = require("./logger")("router-utils");

function urlencoded(limit = "50mb", extended = true) {
return bodyParser.urlencoded({
Expand Down Expand Up @@ -31,17 +32,27 @@ async function tryLogin(req, res, next) {
if (cookie) {
return setUsernameFromCookie(req, res, next);
} else if (clientId) {
const { username, state } = await cloud.getClientInfo(clientId);
req.username = username;
req.clientState = state;
try {
const { username, state } = await cloud.getClientInfo(clientId);
req.username = username;
req.clientState = state;
} catch (e) {
logger.error(`tryLogin failed clientId=${clientId} -> cloud error ${e}`);
}
}
next();
}

async function setUsernameFromCookie(req, res, next) {
const cookie = req.cookies.netsblox;
const username = await cloud.whoami(cookie);
req.username = username;
try {
const username = await cloud.whoami(cookie);
req.username = username;
} catch (e) {
logger.error(
`setUsernameFromCookie failed cookie=${cookie} -> cloud error ${e}`,
);
}
next();
}

Expand Down

0 comments on commit be2dcb2

Please sign in to comment.