Fix invite problem on backend

This commit is contained in:
x032205
2025-06-03 21:06:48 -04:00
parent b7b36a475d
commit aa049dc43b
5 changed files with 10 additions and 28 deletions

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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

View File

@@ -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) {

View File

@@ -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"))