Reauthenticating for every connect attempt to ensure session is still valid.

This commit is contained in:
ThePendulum 2022-01-06 23:55:41 +01:00
parent 497e52be38
commit e87e6d47f9
1 changed files with 9 additions and 8 deletions

View File

@ -260,10 +260,16 @@ function handleError(error, socket, domain, data) {
}
}
async function connect(wsCreds, sessionCookie, bot, games) {
async function connect(bot, games) {
const socket = { ws: { readyState: 0 } };
socket.connect = () => {
socket.connect = async () => {
const { user, httpSession, sessionCookie } = await auth();
const wsCreds = await getWsId(httpSession);
bot.user = user;
bot.httpSession = httpSession;
logger.info(`Attempting to connect to ${config.socket}`);
socket.ws = new WebSocket(`${config.socket}?${new URLSearchParams({ v: wsCreds.wsId, t: wsCreds.timestamp }).toString()}`, [], {
@ -310,19 +316,14 @@ async function connect(wsCreds, sessionCookie, bot, games) {
}
async function init() {
const { user, httpSession, sessionCookie } = await auth();
const wsCreds = await getWsId(httpSession);
const bot = {
user,
httpSession,
rooms: [],
users: [],
};
const games = getGames(bot);
bot.socket = await connect(wsCreds, sessionCookie, bot, games);
bot.socket = await connect(bot, games);
await initPoints();
}