Reauthenticating for every connect attempt to ensure session is still valid.
This commit is contained in:
parent
497e52be38
commit
e87e6d47f9
17
src/app.js
17
src/app.js
|
@ -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 } };
|
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}`);
|
logger.info(`Attempting to connect to ${config.socket}`);
|
||||||
|
|
||||||
socket.ws = new WebSocket(`${config.socket}?${new URLSearchParams({ v: wsCreds.wsId, t: wsCreds.timestamp }).toString()}`, [], {
|
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() {
|
async function init() {
|
||||||
const { user, httpSession, sessionCookie } = await auth();
|
|
||||||
const wsCreds = await getWsId(httpSession);
|
|
||||||
|
|
||||||
const bot = {
|
const bot = {
|
||||||
user,
|
|
||||||
httpSession,
|
|
||||||
rooms: [],
|
rooms: [],
|
||||||
users: [],
|
users: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const games = getGames(bot);
|
const games = getGames(bot);
|
||||||
|
|
||||||
bot.socket = await connect(wsCreds, sessionCookie, bot, games);
|
bot.socket = await connect(bot, games);
|
||||||
|
|
||||||
await initPoints();
|
await initPoints();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue