mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 14:27:30 +00:00
Fix: Email signup and switching organization
This commit is contained in:
@@ -108,7 +108,8 @@ export const registerSignupRouter = async (server: FastifyZodProvider) => {
|
|||||||
200: z.object({
|
200: z.object({
|
||||||
message: z.string(),
|
message: z.string(),
|
||||||
user: UsersSchema,
|
user: UsersSchema,
|
||||||
token: z.string()
|
token: z.string(),
|
||||||
|
organizationId: z.string().nullish()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -124,12 +125,13 @@ export const registerSignupRouter = async (server: FastifyZodProvider) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const { user, accessToken, refreshToken } = await server.services.signup.completeEmailAccountSignup({
|
const { user, accessToken, refreshToken, organizationId } =
|
||||||
...req.body,
|
await server.services.signup.completeEmailAccountSignup({
|
||||||
ip: req.realIp,
|
...req.body,
|
||||||
userAgent,
|
ip: req.realIp,
|
||||||
authorization: req.headers.authorization as string
|
userAgent,
|
||||||
});
|
authorization: req.headers.authorization as string
|
||||||
|
});
|
||||||
|
|
||||||
if (user.email) {
|
if (user.email) {
|
||||||
void server.services.telemetry.sendLoopsEvent(user.email, user.firstName || "", user.lastName || "");
|
void server.services.telemetry.sendLoopsEvent(user.email, user.firstName || "", user.lastName || "");
|
||||||
@@ -152,7 +154,7 @@ export const registerSignupRouter = async (server: FastifyZodProvider) => {
|
|||||||
secure: appCfg.HTTPS_ENABLED
|
secure: appCfg.HTTPS_ENABLED
|
||||||
});
|
});
|
||||||
|
|
||||||
return { message: "Successfully set up account", user, token: accessToken };
|
return { message: "Successfully set up account", user, token: accessToken, organizationId };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -150,11 +150,15 @@ export const authSignupServiceFactory = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!organizationId) {
|
if (!organizationId) {
|
||||||
await orgService.createOrganization({
|
const newOrganization = await orgService.createOrganization({
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
userEmail: user.email ?? user.username,
|
userEmail: user.email ?? user.username,
|
||||||
orgName: organizationName
|
orgName: organizationName
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!newOrganization) throw new Error("Failed to create organization");
|
||||||
|
|
||||||
|
organizationId = newOrganization.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
const updatedMembersips = await orgDAL.updateMembership(
|
const updatedMembersips = await orgDAL.updateMembership(
|
||||||
@@ -187,6 +191,7 @@ export const authSignupServiceFactory = ({
|
|||||||
|
|
||||||
const refreshToken = jwt.sign(
|
const refreshToken = jwt.sign(
|
||||||
{
|
{
|
||||||
|
authMethod: AuthMethod.EMAIL,
|
||||||
authTokenType: AuthTokenType.REFRESH_TOKEN,
|
authTokenType: AuthTokenType.REFRESH_TOKEN,
|
||||||
userId: updateduser.info.id,
|
userId: updateduser.info.id,
|
||||||
tokenVersionId: tokenSession.id,
|
tokenVersionId: tokenSession.id,
|
||||||
@@ -197,7 +202,7 @@ export const authSignupServiceFactory = ({
|
|||||||
{ expiresIn: appCfg.JWT_REFRESH_LIFETIME }
|
{ expiresIn: appCfg.JWT_REFRESH_LIFETIME }
|
||||||
);
|
);
|
||||||
|
|
||||||
return { user: updateduser.info, accessToken, refreshToken };
|
return { user: updateduser.info, accessToken, refreshToken, organizationId };
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -290,6 +295,7 @@ export const authSignupServiceFactory = ({
|
|||||||
|
|
||||||
const refreshToken = jwt.sign(
|
const refreshToken = jwt.sign(
|
||||||
{
|
{
|
||||||
|
authMethod: AuthMethod.EMAIL,
|
||||||
authTokenType: AuthTokenType.REFRESH_TOKEN,
|
authTokenType: AuthTokenType.REFRESH_TOKEN,
|
||||||
userId: updateduser.info.id,
|
userId: updateduser.info.id,
|
||||||
tokenVersionId: tokenSession.id,
|
tokenVersionId: tokenSession.id,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import jsrp from "jsrp";
|
|||||||
import nacl from "tweetnacl";
|
import nacl from "tweetnacl";
|
||||||
import { encodeBase64 } from "tweetnacl-util";
|
import { encodeBase64 } from "tweetnacl-util";
|
||||||
|
|
||||||
import { completeAccountSignup } from "@app/hooks/api/auth/queries";
|
import { completeAccountSignup, useSelectOrganization } from "@app/hooks/api/auth/queries";
|
||||||
import { fetchOrganizations } from "@app/hooks/api/organization/queries";
|
import { fetchOrganizations } from "@app/hooks/api/organization/queries";
|
||||||
import ProjectService from "@app/services/ProjectService";
|
import ProjectService from "@app/services/ProjectService";
|
||||||
|
|
||||||
@@ -79,6 +79,7 @@ export default function UserInfoStep({
|
|||||||
|
|
||||||
const [errors, setErrors] = useState<Errors>({});
|
const [errors, setErrors] = useState<Errors>({});
|
||||||
|
|
||||||
|
const { mutateAsync: selectOrganization } = useSelectOrganization();
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
@@ -181,6 +182,10 @@ export default function UserInfoStep({
|
|||||||
SecurityClient.setToken(response.token);
|
SecurityClient.setToken(response.token);
|
||||||
SecurityClient.setProviderAuthToken("");
|
SecurityClient.setProviderAuthToken("");
|
||||||
|
|
||||||
|
if (response.organizationId) {
|
||||||
|
await selectOrganization({ organizationId: response.organizationId });
|
||||||
|
}
|
||||||
|
|
||||||
saveTokenToLocalStorage({
|
saveTokenToLocalStorage({
|
||||||
publicKey,
|
publicKey,
|
||||||
encryptedPrivateKey,
|
encryptedPrivateKey,
|
||||||
|
|||||||
@@ -68,8 +68,10 @@ import {
|
|||||||
useGetSecretApprovalRequestCount,
|
useGetSecretApprovalRequestCount,
|
||||||
useGetUserAction,
|
useGetUserAction,
|
||||||
useLogoutUser,
|
useLogoutUser,
|
||||||
useRegisterUserAction
|
useRegisterUserAction,
|
||||||
|
useSelectOrganization
|
||||||
} from "@app/hooks/api";
|
} from "@app/hooks/api";
|
||||||
|
import { navigateUserToOrg } from "@app/views/Login/Login.utils";
|
||||||
import { CreateOrgModal } from "@app/views/Org/components";
|
import { CreateOrgModal } from "@app/views/Org/components";
|
||||||
|
|
||||||
interface LayoutProps {
|
interface LayoutProps {
|
||||||
@@ -100,7 +102,12 @@ const supportOptions = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
const formSchema = yup.object({
|
const formSchema = yup.object({
|
||||||
name: yup.string().required().label("Project Name").trim().max(64, "Too long, maximum length is 64 characters"),
|
name: yup
|
||||||
|
.string()
|
||||||
|
.required()
|
||||||
|
.label("Project Name")
|
||||||
|
.trim()
|
||||||
|
.max(64, "Too long, maximum length is 64 characters"),
|
||||||
addMembers: yup.bool().required().label("Add Members")
|
addMembers: yup.bool().required().label("Add Members")
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -147,6 +154,7 @@ export const AppLayout = ({ children }: LayoutProps) => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const registerUserAction = useRegisterUserAction();
|
const registerUserAction = useRegisterUserAction();
|
||||||
|
const { mutateAsync: selectOrganization } = useSelectOrganization();
|
||||||
|
|
||||||
const closeUpdate = async () => {
|
const closeUpdate = async () => {
|
||||||
await registerUserAction.mutateAsync("december_update_closed");
|
await registerUserAction.mutateAsync("december_update_closed");
|
||||||
@@ -164,8 +172,11 @@ export const AppLayout = ({ children }: LayoutProps) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const changeOrg = async (orgId: string) => {
|
const changeOrg = async (orgId: string) => {
|
||||||
localStorage.setItem("orgData.id", orgId);
|
await selectOrganization({
|
||||||
router.push(`/org/${orgId}/overview`);
|
organizationId: orgId
|
||||||
|
});
|
||||||
|
|
||||||
|
await navigateUserToOrg(router, orgId);
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO(akhilmhdh): This entire logic will be rechecked and will try to avoid
|
// TODO(akhilmhdh): This entire logic will be rechecked and will try to avoid
|
||||||
@@ -425,7 +436,7 @@ export const AppLayout = ({ children }: LayoutProps) => {
|
|||||||
<Select
|
<Select
|
||||||
defaultValue={currentWorkspace?.id}
|
defaultValue={currentWorkspace?.id}
|
||||||
value={currentWorkspace?.id}
|
value={currentWorkspace?.id}
|
||||||
className="w-full [&>*:first-child]:truncate bg-mineshaft-600 py-2.5 font-medium"
|
className="w-full bg-mineshaft-600 py-2.5 font-medium [&>*:first-child]:truncate"
|
||||||
onValueChange={(value) => {
|
onValueChange={(value) => {
|
||||||
router.push(`/project/${value}/secrets/overview`);
|
router.push(`/project/${value}/secrets/overview`);
|
||||||
localStorage.setItem("projectData.id", value);
|
localStorage.setItem("projectData.id", value);
|
||||||
|
|||||||
Reference in New Issue
Block a user