mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-05 17:26:36 +00:00
Merge pull request #1429 from akhilmhdh/fix/admin-fail-redirect
fix(admin): resolved undefined on redirect after admin signup
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { SuperAdminSchema, UsersSchema } from "@app/db/schemas";
|
import { OrganizationsSchema, SuperAdminSchema, UsersSchema } from "@app/db/schemas";
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig } from "@app/lib/config/env";
|
||||||
import { UnauthorizedError } from "@app/lib/errors";
|
import { UnauthorizedError } from "@app/lib/errors";
|
||||||
import { verifySuperAdmin } from "@app/server/plugins/auth/superAdmin";
|
import { verifySuperAdmin } from "@app/server/plugins/auth/superAdmin";
|
||||||
@@ -72,6 +72,7 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {
|
|||||||
200: z.object({
|
200: z.object({
|
||||||
message: z.string(),
|
message: z.string(),
|
||||||
user: UsersSchema,
|
user: UsersSchema,
|
||||||
|
organization: OrganizationsSchema,
|
||||||
token: z.string(),
|
token: z.string(),
|
||||||
new: z.string()
|
new: z.string()
|
||||||
})
|
})
|
||||||
@@ -82,7 +83,7 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {
|
|||||||
const serverCfg = await getServerCfg();
|
const serverCfg = await getServerCfg();
|
||||||
if (serverCfg.initialized)
|
if (serverCfg.initialized)
|
||||||
throw new UnauthorizedError({ name: "Admin sign up", message: "Admin has been created" });
|
throw new UnauthorizedError({ name: "Admin sign up", message: "Admin has been created" });
|
||||||
const { user, token } = await server.services.superAdmin.adminSignUp({
|
const { user, token, organization } = await server.services.superAdmin.adminSignUp({
|
||||||
...req.body,
|
...req.body,
|
||||||
ip: req.realIp,
|
ip: req.realIp,
|
||||||
userAgent: req.headers["user-agent"] || ""
|
userAgent: req.headers["user-agent"] || ""
|
||||||
@@ -109,6 +110,7 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {
|
|||||||
message: "Successfully set up admin account",
|
message: "Successfully set up admin account",
|
||||||
user: user.user,
|
user: user.user,
|
||||||
token: token.access,
|
token: token.access,
|
||||||
|
organization,
|
||||||
new: "123"
|
new: "123"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,11 @@ export const superAdminServiceFactory = ({
|
|||||||
|
|
||||||
const initialOrganizationName = appCfg.INITIAL_ORGANIZATION_NAME ?? "Admin Org";
|
const initialOrganizationName = appCfg.INITIAL_ORGANIZATION_NAME ?? "Admin Org";
|
||||||
|
|
||||||
await orgService.createOrganization(userInfo.user.id, userInfo.user.email, initialOrganizationName);
|
const organization = await orgService.createOrganization(
|
||||||
|
userInfo.user.id,
|
||||||
|
userInfo.user.email,
|
||||||
|
initialOrganizationName
|
||||||
|
);
|
||||||
|
|
||||||
await updateServerCfg({ initialized: true });
|
await updateServerCfg({ initialized: true });
|
||||||
const token = await authService.generateUserTokens({
|
const token = await authService.generateUserTokens({
|
||||||
@@ -106,7 +110,7 @@ export const superAdminServiceFactory = ({
|
|||||||
organizationId: undefined
|
organizationId: undefined
|
||||||
});
|
});
|
||||||
// TODO(akhilmhdh-pg): telemetry service
|
// TODO(akhilmhdh-pg): telemetry service
|
||||||
return { token, user: userInfo };
|
return { token, user: userInfo, organization };
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|||||||
|
|
||||||
import { apiRequest } from "@app/config/request";
|
import { apiRequest } from "@app/config/request";
|
||||||
|
|
||||||
|
import { organizationKeys } from "../organization/queries";
|
||||||
import { User } from "../users/types";
|
import { User } from "../users/types";
|
||||||
import { adminQueryKeys } from "./queries";
|
import { adminQueryKeys } from "./queries";
|
||||||
import { TCreateAdminUserDTO, TServerConfig } from "./types";
|
import { TCreateAdminUserDTO, TServerConfig } from "./types";
|
||||||
@@ -9,7 +10,11 @@ import { TCreateAdminUserDTO, TServerConfig } from "./types";
|
|||||||
export const useCreateAdminUser = () => {
|
export const useCreateAdminUser = () => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
return useMutation<{ user: User; token: string }, {}, TCreateAdminUserDTO>({
|
return useMutation<
|
||||||
|
{ user: User; token: string; organization: { id: string } },
|
||||||
|
{},
|
||||||
|
TCreateAdminUserDTO
|
||||||
|
>({
|
||||||
mutationFn: async (opt) => {
|
mutationFn: async (opt) => {
|
||||||
const { data } = await apiRequest.post("/api/v1/admin/signup", opt);
|
const { data } = await apiRequest.post("/api/v1/admin/signup", opt);
|
||||||
return data;
|
return data;
|
||||||
@@ -34,6 +39,7 @@ export const useUpdateServerConfig = () => {
|
|||||||
onSuccess: (data) => {
|
onSuccess: (data) => {
|
||||||
queryClient.setQueryData(adminQueryKeys.serverConfig(), data);
|
queryClient.setQueryData(adminQueryKeys.serverConfig(), data);
|
||||||
queryClient.invalidateQueries(adminQueryKeys.serverConfig());
|
queryClient.invalidateQueries(adminQueryKeys.serverConfig());
|
||||||
|
queryClient.invalidateQueries(organizationKeys.getUserOrganizations);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -84,6 +84,10 @@ export const SignUpPage = () => {
|
|||||||
tag: userPass.encryptedPrivateKeyTag,
|
tag: userPass.encryptedPrivateKeyTag,
|
||||||
privateKey
|
privateKey
|
||||||
});
|
});
|
||||||
|
// TODO(akhilmhdh): This is such a confusing pattern and too unreliable
|
||||||
|
// Will be refactored in next iteration to make it url based rather than local storage ones
|
||||||
|
// Part of migration to nextjs 14
|
||||||
|
localStorage.setItem("orgData.id", res.organization.id);
|
||||||
setStep(SignupSteps.BackupKey);
|
setStep(SignupSteps.BackupKey);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@@ -130,8 +134,8 @@ export const SignUpPage = () => {
|
|||||||
>
|
>
|
||||||
<div className="flex flex-col items-center space-y-2 text-center">
|
<div className="flex flex-col items-center space-y-2 text-center">
|
||||||
<img src="/images/gradientLogo.svg" height={90} width={120} alt="Infisical logo" />
|
<img src="/images/gradientLogo.svg" height={90} width={120} alt="Infisical logo" />
|
||||||
<div className="text-4xl pt-4">Welcome to Infisical</div>
|
<div className="pt-4 text-4xl">Welcome to Infisical</div>
|
||||||
<div className="text-bunker-300 pb-4">Create your first Super Admin Account</div>
|
<div className="pb-4 text-bunker-300">Create your first Super Admin Account</div>
|
||||||
</div>
|
</div>
|
||||||
<form onSubmit={handleSubmit(handleFormSubmit)}>
|
<form onSubmit={handleSubmit(handleFormSubmit)}>
|
||||||
<div className="mt-8">
|
<div className="mt-8">
|
||||||
@@ -199,7 +203,14 @@ export const SignUpPage = () => {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Button type="submit" colorSchema="primary" variant="outline_bg" isFullWidth className="mt-4" isLoading={isSubmitting}>
|
<Button
|
||||||
|
type="submit"
|
||||||
|
colorSchema="primary"
|
||||||
|
variant="outline_bg"
|
||||||
|
isFullWidth
|
||||||
|
className="mt-4"
|
||||||
|
isLoading={isSubmitting}
|
||||||
|
>
|
||||||
Continue
|
Continue
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Reference in New Issue
Block a user