Adding: themes, predictions, match reporting, ui fixes, sse fixes, badge fixes, match flow, i18n, match edits, perf, auth fix #22
@@ -159,16 +159,29 @@ export function useServerEvents() {
|
|||||||
logger.error("SSE connection error", error);
|
logger.error("SSE connection error", error);
|
||||||
disconnect();
|
disconnect();
|
||||||
|
|
||||||
|
// The stream is auth-guarded, so an error is often the server rejecting
|
||||||
|
// an expired session rather than a network blip. Try to refresh; if the
|
||||||
|
// session is genuinely gone, stop retrying so we don't hammer the
|
||||||
|
// endpoint forever — a real re-login (or a wake event) will reconnect.
|
||||||
|
let sessionValid = true;
|
||||||
|
try {
|
||||||
|
const { attemptRefreshingSession } = await import('supertokens-web-js/recipe/session');
|
||||||
|
sessionValid = await attemptRefreshingSession();
|
||||||
|
} catch {
|
||||||
|
// Refresh call itself failed (likely offline) — treat as transient.
|
||||||
|
}
|
||||||
|
|
||||||
|
if (disposed) return;
|
||||||
|
|
||||||
|
if (!sessionValid) {
|
||||||
|
logger.warn("SSE stopped: session is no longer valid");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
retryCount += 1;
|
retryCount += 1;
|
||||||
const delay = Math.min(1000 * Math.pow(1.5, retryCount - 1), 15000);
|
const delay = Math.min(1000 * Math.pow(1.5, retryCount - 1), 15000);
|
||||||
logger.info(`SSE reconnection attempt ${retryCount} in ${Math.round(delay)}ms`);
|
logger.info(`SSE reconnection attempt ${retryCount} in ${Math.round(delay)}ms`);
|
||||||
|
|
||||||
try {
|
|
||||||
const { attemptRefreshingSession } = await import('supertokens-web-js/recipe/session');
|
|
||||||
await attemptRefreshingSession();
|
|
||||||
} catch {
|
|
||||||
}
|
|
||||||
|
|
||||||
reconnect(delay);
|
reconnect(delay);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ const verifySuperTokensSession = async (request: Request) => {
|
|||||||
const userAuthId = session?.userId;
|
const userAuthId = session?.userId;
|
||||||
|
|
||||||
if (!userAuthId || !session) {
|
if (!userAuthId || !session) {
|
||||||
logger.info("No authenticated user");
|
|
||||||
return { context: { userAuthId: null, roles: [] } };
|
return { context: { userAuthId: null, roles: [] } };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +108,6 @@ export const getSessionContextCore = async (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!session.context.userAuthId) {
|
if (!session.context.userAuthId) {
|
||||||
logger.error("Unauthenticated user", session.context);
|
|
||||||
throw new Error("Unauthenticated");
|
throw new Error("Unauthenticated");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user