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
@@ -397,7 +397,7 @@ export const authLoginServiceFactory = ({
// Check if the user actually has access to the specified organization. // Check if the user actually has access to the specified organization.
const userOrgs = await orgDAL.findAllOrgsByUserId(user.id); 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); const selectedOrg = await orgDAL.findById(organizationId);
if (!hasOrganizationMembership) { if (!hasOrganizationMembership) {
+3 -2
View File
@@ -212,7 +212,7 @@ export const orgDALFactory = (db: TDbClient) => {
// special query // special query
const findAllOrgsByUserId = async ( const findAllOrgsByUserId = async (
userId: string userId: string
): Promise<(TOrganizations & { orgAuthMethod: string; userRole: string })[]> => { ): Promise<(TOrganizations & { orgAuthMethod: string; userRole: string; userStatus: string })[]> => {
try { try {
const org = (await db const org = (await db
.replicaNode()(TableName.OrgMembership) .replicaNode()(TableName.OrgMembership)
@@ -234,6 +234,7 @@ export const orgDALFactory = (db: TDbClient) => {
}) })
.select(selectAllTableCols(TableName.Organization)) .select(selectAllTableCols(TableName.Organization))
.select(db.ref("role").withSchema(TableName.OrgMembership).as("userRole")) .select(db.ref("role").withSchema(TableName.OrgMembership).as("userRole"))
.select(db.ref("status").withSchema(TableName.OrgMembership).as("userStatus"))
.select( .select(
db.raw(` db.raw(`
CASE CASE
@@ -242,7 +243,7 @@ export const orgDALFactory = (db: TDbClient) => {
ELSE '' ELSE ''
END as "orgAuthMethod" END as "orgAuthMethod"
`) `)
)) as (TOrganizations & { orgAuthMethod: string; userRole: string })[]; )) as (TOrganizations & { orgAuthMethod: string; userRole: string; userStatus: string })[];
return org; return org;
} catch (error) { } catch (error) {
+3 -1
View File
@@ -183,7 +183,9 @@ export const orgServiceFactory = ({
* */ * */
const findAllOrganizationOfUser = async (userId: string) => { const findAllOrganizationOfUser = async (userId: string) => {
const orgs = await orgDAL.findAllOrgsByUserId(userId); 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 * Get all workspace members
@@ -243,28 +243,7 @@ export const SignupInvitePage = () => {
SecurityClient.setSignupToken(response.token); SecurityClient.setSignupToken(response.token);
setStep(2); setStep(2);
} else { } else {
const redirectExistingUser = async () => { navigate({ to: "/login" });
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();
} }
} }
} catch (err) { } catch (err) {
@@ -74,6 +74,8 @@ export const Route = createFileRoute("/_restrict-login-signup")({
middlewares: [stripSearchParams({ callback_port: undefined })] middlewares: [stripSearchParams({ callback_port: undefined })]
}, },
beforeLoad: async ({ context, location, search }) => { beforeLoad: async ({ context, location, search }) => {
if (location.pathname === "/signupinvite") return;
if (!context.serverConfig.initialized) { if (!context.serverConfig.initialized) {
if (location.pathname.endsWith("/admin/signup")) return; if (location.pathname.endsWith("/admin/signup")) return;
throw redirect({ to: "/admin/signup" }); throw redirect({ to: "/admin/signup" });
@@ -91,8 +93,6 @@ export const Route = createFileRoute("/_restrict-login-signup")({
setAuthToken(data.token); setAuthToken(data.token);
if (location.pathname === "/signupinvite") return;
// to do cli login // to do cli login
if (search?.callback_port) { if (search?.callback_port) {
if (location.pathname.endsWith("select-organization") || location.pathname.endsWith("login")) if (location.pathname.endsWith("select-organization") || location.pathname.endsWith("login"))