Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 3x | import { QueryClient } from "@tanstack/react-query";
import { redirect } from "react-router";
import { getUser } from "@/api";
import { createUserProfile } from "@/api/useCreateUserProfile";
import { requestBaseCMSAccess } from "@/api/useRequestBaseCMSAccess";
export const loader = (queryClient: QueryClient, loginFlag?: boolean) => {
return async () => {
const queryString = window.location.search;
// Parse the query string to get URL parameters
const queryParams = new URLSearchParams(queryString);
// Access specific parameters
const errorDescription = queryParams.get("error_description");
const error = queryParams.get("error");
Iif (errorDescription || error) {
console.error("Authentication Error:", { errorDescription, error });
return { error };
}
await requestBaseCMSAccess();
await createUserProfile();
// check user query has been initialized
Eif (!queryClient.getQueryData(["user"])) {
const userFetch = await queryClient.fetchQuery({
queryKey: ["user"],
queryFn: () => getUser(),
});
const isUserLoggedIn =
!["/login", "/faq", "/support"].includes(window.location.pathname) && !userFetch?.user;
if (!loginFlag && isUserLoggedIn) {
return redirect("/login");
}
}
return queryClient.getQueryData(["user"]);
};
};
|