mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 09:30:09 +00:00
Fix case where user can get stuck in a deleted organization if they were prev logged into it
This commit is contained in:
@@ -5,12 +5,15 @@ import { ROUTE_PATHS } from "@app/const/routes";
|
||||
import { userKeys } from "@app/hooks/api";
|
||||
import { authKeys, fetchAuthToken } from "@app/hooks/api/auth/queries";
|
||||
import { fetchUserDetails } from "@app/hooks/api/users/queries";
|
||||
import { AxiosError } from "axios";
|
||||
import { clearSession, logoutUser } from "@app/hooks/api/users/queries";
|
||||
|
||||
export const Route = createFileRoute("/_authenticate")({
|
||||
beforeLoad: async ({ context, location }) => {
|
||||
if (!context.serverConfig.initialized) {
|
||||
throw redirect({ to: "/admin/signup" });
|
||||
}
|
||||
|
||||
const data = await context.queryClient
|
||||
.ensureQueryData({
|
||||
queryKey: authKeys.getAuthToken,
|
||||
@@ -27,14 +30,31 @@ export const Route = createFileRoute("/_authenticate")({
|
||||
});
|
||||
});
|
||||
|
||||
if (!data.organizationId && location.pathname !== ROUTE_PATHS.Auth.PasswordSetupPage.path && location.pathname !== "/organization/none") {
|
||||
if (
|
||||
!data.organizationId &&
|
||||
location.pathname !== ROUTE_PATHS.Auth.PasswordSetupPage.path &&
|
||||
location.pathname !== "/organization/none"
|
||||
) {
|
||||
throw redirect({ to: "/login/select-organization" });
|
||||
}
|
||||
|
||||
const user = await context.queryClient.ensureQueryData({
|
||||
queryKey: userKeys.getUser,
|
||||
queryFn: fetchUserDetails
|
||||
});
|
||||
const user = await context.queryClient
|
||||
.ensureQueryData({
|
||||
queryKey: userKeys.getUser,
|
||||
queryFn: fetchUserDetails
|
||||
})
|
||||
.catch(async (error) => {
|
||||
const err = error as AxiosError;
|
||||
if (err.response?.status === 403) {
|
||||
// (dangtony98): this edge-case can occur if the user's token corresponds to an organization
|
||||
// that has been deleted for which we must clear the refresh token in http-only cookie
|
||||
clearSession(true);
|
||||
await logoutUser();
|
||||
throw redirect({
|
||||
to: "/login"
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return { organizationId: data.organizationId as string, isAuthenticated: true, user };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user