Skip to content

Commit e3a6579

Browse files
committed
Rename sessionValid to runSessionValidationCheck
As the function has a side-effect on the localStorage values, the old name was misleading in it's effects
1 parent 75a9ec0 commit e3a6579

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

apps/cyberstorm-remix/app/root.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import {
4343
getSessionContext,
4444
getSessionStale,
4545
SESSION_STORAGE_KEY,
46-
sessionValid,
46+
runSessionValidationCheck,
4747
} from "@thunderstore/ts-api-react/src/SessionContext";
4848
import {
4949
getPublicEnvVariables,
@@ -152,12 +152,12 @@ export async function clientLoader({ request }: Route.ClientLoaderArgs) {
152152
} else {
153153
// In all other cases check if actually need to fetch
154154
// current-user data. Ideally we shouldn't need to do
155-
// this sessionValid check again, but for some reason
155+
// this runSessionValidationCheck check again, but for some reason
156156
// we need to run this here too in addition to the,
157157
// shouldRevalidate function, cause for some reason
158158
// the commits to localStorage are not done before
159159
// the clientLoader is run.
160-
sessionTools.sessionValid(
160+
sessionTools.runSessionValidationCheck(
161161
publicEnvVariables.VITE_API_URL,
162162
publicEnvVariables.VITE_COOKIE_DOMAIN
163163
);
@@ -191,7 +191,7 @@ export function shouldRevalidate({
191191
nextUrl.pathname.startsWith("/settings")
192192
)
193193
return true;
194-
sessionValid(
194+
runSessionValidationCheck(
195195
new StorageManager(SESSION_STORAGE_KEY),
196196
publicEnvVariables.VITE_API_URL || "",
197197
publicEnvVariables.VITE_COOKIE_DOMAIN || ""

packages/ts-api-react/src/SessionContext.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface ContextInterface {
2626
/** Get RequestConfig for Dapper usage */
2727
getConfig: (domain?: string) => RequestConfig;
2828
/** Check if session is valid and try to repair if not */
29-
sessionValid: (apiHost: string, cookieDomain: string) => boolean;
29+
runSessionValidationCheck: (apiHost: string, cookieDomain: string) => boolean;
3030
/** apiHost of the session */
3131
apiHost?: string;
3232
/** Async function to update currentUser */
@@ -120,7 +120,7 @@ function parseCurrentUser(currentUser: unknown): User {
120120
}
121121
}
122122

123-
export const sessionValid = (
123+
export const runSessionValidationCheck = (
124124
_storage: StorageManager,
125125
apiHost: string,
126126
cookieDomain: string
@@ -252,8 +252,11 @@ export const getSessionContext = (
252252
};
253253

254254
// Check current session and try to fix it if cookies are not the same as storage
255-
const _sessionValid = (apiHost: string, cookieDomain: string): boolean => {
256-
return sessionValid(_storage, apiHost, cookieDomain);
255+
const _runSessionValidationCheck = (
256+
apiHost: string,
257+
cookieDomain: string
258+
): boolean => {
259+
return runSessionValidationCheck(_storage, apiHost, cookieDomain);
257260
};
258261

259262
const _storeCurrentUser = (currentUser: User) => {
@@ -279,15 +282,15 @@ export const getSessionContext = (
279282
});
280283
} else {
281284
_storage.setValue(API_HOST_KEY, apiHost);
282-
_sessionValid(apiHost, cookieDomain);
285+
_runSessionValidationCheck(apiHost, cookieDomain);
283286
}
284287
}
285288

286289
return {
287290
clearSession: _clearSession,
288291
clearCookies: _clearCookies,
289292
getConfig: _getConfig,
290-
sessionValid: _sessionValid,
293+
runSessionValidationCheck: _runSessionValidationCheck,
291294
updateCurrentUser: _updateCurrentUser,
292295
storeCurrentUser: _storeCurrentUser,
293296
getSessionCurrentUser: _getSessionCurrentUser,

packages/ts-api-react/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export {
44
setSession,
55
clearSession,
66
getConfig,
7-
sessionValid,
7+
runSessionValidationCheck,
88
storeCurrentUser,
99
updateCurrentUser,
1010
getSessionCurrentUser,

0 commit comments

Comments
 (0)