fix token bug?

This commit is contained in:
Hri7566 2024-11-04 21:19:25 -05:00
parent a7e4902b7e
commit e4e13a896f
1 changed files with 6 additions and 2 deletions

View File

@ -52,18 +52,20 @@ export const hi: ServerEventListener<"hi"> = {
if (config.tokenAuth !== "none") { if (config.tokenAuth !== "none") {
if (typeof msg.token !== "string") { if (typeof msg.token !== "string") {
socket.gateway.hasSentToken = true;
// Get a saved token // Get a saved token
token = await getToken(socket.getUserID()); token = await getToken(socket.getUserID());
// Does it exist?
if (typeof token !== "string") { if (typeof token !== "string") {
// Generate a new one // Generate a new one
token = await createToken( token = await createToken(
socket.getUserID(), socket.getUserID(),
socket.gateway socket.gateway
); );
socket.gateway.isTokenValid = true; socket.gateway.isTokenValid = true;
// Does it exist? (again)
if (typeof token !== "string") { if (typeof token !== "string") {
logger.warn( logger.warn(
`Unable to generate token for user ${socket.getUserID()}` `Unable to generate token for user ${socket.getUserID()}`
@ -73,6 +75,8 @@ export const hi: ServerEventListener<"hi"> = {
} }
} }
} else { } else {
socket.gateway.hasSentToken = true;
// Validate the token // Validate the token
const valid = await validateToken( const valid = await validateToken(
socket.getUserID(), socket.getUserID(),