Skip to content

Commit cbe1789

Browse files
committed
Add forced currentUser update to settings and teams pages
1 parent f446eed commit cbe1789

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

apps/cyberstorm-remix/app/root.tsx

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import {
5050
publicEnvVariablesType,
5151
} from "cyberstorm/security/publicEnvVariables";
5252
import { StorageManager } from "@thunderstore/ts-api-react/src/storage";
53+
import { Route } from "./+types/root";
5354

5455
// REMIX TODO: https://remix.run/docs/en/main/route/links
5556
// export const links: LinksFunction = () => [{ rel: "stylesheet", href: styles }];
@@ -119,7 +120,7 @@ export async function loader() {
119120
};
120121
}
121122

122-
export async function clientLoader() {
123+
export async function clientLoader({ request }: Route.ClientLoaderArgs) {
123124
const publicEnvVariables = getPublicEnvVariables([
124125
"VITE_SITE_URL",
125126
"VITE_BETA_SITE_URL",
@@ -142,13 +143,28 @@ export async function clientLoader() {
142143
publicEnvVariables.VITE_COOKIE_DOMAIN
143144
);
144145

145-
// We need to run this here too in addition to the, shouldRevalidate function,
146-
// as for some reason the commtis to localStorage are not done before the the clientLoader is run
147-
sessionTools.sessionValid(
148-
publicEnvVariables.VITE_API_URL,
149-
publicEnvVariables.VITE_COOKIE_DOMAIN
146+
let forceUpdateCurrentUser = false;
147+
if (
148+
request.url.startsWith(`${publicEnvVariables.VITE_BETA_SITE_URL}/teams`) ||
149+
request.url.startsWith(`${publicEnvVariables.VITE_BETA_SITE_URL}/settings`)
150+
) {
151+
forceUpdateCurrentUser = true;
152+
} else {
153+
// In all other cases check if actually need to fetch
154+
// current-user data. Ideally we shouldn't need to do
155+
// this sessionValid check again, but for some reason
156+
// we need to run this here too in addition to the,
157+
// shouldRevalidate function, cause for some reason
158+
// the commits to localStorage are not done before
159+
// the clientLoader is run.
160+
sessionTools.sessionValid(
161+
publicEnvVariables.VITE_API_URL,
162+
publicEnvVariables.VITE_COOKIE_DOMAIN
163+
);
164+
}
165+
const currentUser = await sessionTools.getSessionCurrentUser(
166+
forceUpdateCurrentUser
150167
);
151-
const currentUser = await sessionTools.getSessionCurrentUser();
152168
const config = sessionTools.getConfig(publicEnvVariables.VITE_API_URL);
153169
return {
154170
publicEnvVariables: publicEnvVariables,
@@ -164,11 +180,17 @@ export type RootLoadersType = typeof loader | typeof clientLoader;
164180
// this needs to be fixed, but it requires a more in-depth solution
165181
export function shouldRevalidate({
166182
defaultShouldRevalidate,
183+
nextUrl,
167184
}: ShouldRevalidateFunctionArgs) {
168185
const publicEnvVariables = getPublicEnvVariables([
169186
"VITE_API_URL",
170187
"VITE_COOKIE_DOMAIN",
171188
]);
189+
if (
190+
nextUrl.pathname.startsWith("/teams") ||
191+
nextUrl.pathname.startsWith("/settings")
192+
)
193+
return true;
172194
sessionValid(
173195
new StorageManager(SESSION_STORAGE_KEY),
174196
publicEnvVariables.VITE_API_URL || "",

0 commit comments

Comments
 (0)