mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Fix invite problem on backend
This commit is contained in:
@@ -397,7 +397,7 @@ export const authLoginServiceFactory = ({
|
||||
|
||||
// Check if the user actually has access to the specified organization.
|
||||
const userOrgs = await orgDAL.findAllOrgsByUserId(user.id);
|
||||
const hasOrganizationMembership = userOrgs.some((org) => org.id === organizationId);
|
||||
const hasOrganizationMembership = userOrgs.some((org) => org.id === organizationId && org.userStatus !== "invited");
|
||||
const selectedOrg = await orgDAL.findById(organizationId);
|
||||
|
||||
if (!hasOrganizationMembership) {
|
||||
|
||||
@@ -212,7 +212,7 @@ export const orgDALFactory = (db: TDbClient) => {
|
||||
// special query
|
||||
const findAllOrgsByUserId = async (
|
||||
userId: string
|
||||
): Promise<(TOrganizations & { orgAuthMethod: string; userRole: string })[]> => {
|
||||
): Promise<(TOrganizations & { orgAuthMethod: string; userRole: string; userStatus: string })[]> => {
|
||||
try {
|
||||
const org = (await db
|
||||
.replicaNode()(TableName.OrgMembership)
|
||||
@@ -234,6 +234,7 @@ export const orgDALFactory = (db: TDbClient) => {
|
||||
})
|
||||
.select(selectAllTableCols(TableName.Organization))
|
||||
.select(db.ref("role").withSchema(TableName.OrgMembership).as("userRole"))
|
||||
.select(db.ref("status").withSchema(TableName.OrgMembership).as("userStatus"))
|
||||
.select(
|
||||
db.raw(`
|
||||
CASE
|
||||
@@ -242,7 +243,7 @@ export const orgDALFactory = (db: TDbClient) => {
|
||||
ELSE ''
|
||||
END as "orgAuthMethod"
|
||||
`)
|
||||
)) as (TOrganizations & { orgAuthMethod: string; userRole: string })[];
|
||||
)) as (TOrganizations & { orgAuthMethod: string; userRole: string; userStatus: string })[];
|
||||
|
||||
return org;
|
||||
} catch (error) {
|
||||
|
||||
@@ -183,7 +183,9 @@ export const orgServiceFactory = ({
|
||||
* */
|
||||
const findAllOrganizationOfUser = async (userId: string) => {
|
||||
const orgs = await orgDAL.findAllOrgsByUserId(userId);
|
||||
return orgs;
|
||||
|
||||
// Filter out orgs where the membership object is an invitation
|
||||
return orgs.filter((org) => org.userStatus !== "invited");
|
||||
};
|
||||
/*
|
||||
* Get all workspace members
|
||||
|
||||
@@ -243,28 +243,7 @@ export const SignupInvitePage = () => {
|
||||
SecurityClient.setSignupToken(response.token);
|
||||
setStep(2);
|
||||
} else {
|
||||
const redirectExistingUser = async () => {
|
||||
try {
|
||||
const { token: mfaToken, isMfaEnabled } = await selectOrganization({
|
||||
organizationId
|
||||
});
|
||||
|
||||
if (isMfaEnabled) {
|
||||
SecurityClient.setMfaToken(mfaToken);
|
||||
toggleShowMfa.on();
|
||||
setMfaSuccessCallback(() => redirectExistingUser);
|
||||
return;
|
||||
}
|
||||
|
||||
// user will be redirected to dashboard
|
||||
// if not logged in gets kicked out to login
|
||||
await navigateUserToOrg(navigate, organizationId);
|
||||
} catch (err) {
|
||||
navigate({ to: "/login" });
|
||||
}
|
||||
};
|
||||
|
||||
await redirectExistingUser();
|
||||
navigate({ to: "/login" });
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
@@ -74,6 +74,8 @@ export const Route = createFileRoute("/_restrict-login-signup")({
|
||||
middlewares: [stripSearchParams({ callback_port: undefined })]
|
||||
},
|
||||
beforeLoad: async ({ context, location, search }) => {
|
||||
if (location.pathname === "/signupinvite") return;
|
||||
|
||||
if (!context.serverConfig.initialized) {
|
||||
if (location.pathname.endsWith("/admin/signup")) return;
|
||||
throw redirect({ to: "/admin/signup" });
|
||||
@@ -91,8 +93,6 @@ export const Route = createFileRoute("/_restrict-login-signup")({
|
||||
|
||||
setAuthToken(data.token);
|
||||
|
||||
if (location.pathname === "/signupinvite") return;
|
||||
|
||||
// to do cli login
|
||||
if (search?.callback_port) {
|
||||
if (location.pathname.endsWith("select-organization") || location.pathname.endsWith("login"))
|
||||
|
||||
Reference in New Issue
Block a user