fix: it was possible to go to the create user page when credentials login disabled (#1217)
This commit is contained in:
@@ -15,9 +15,10 @@ import { useTranslatedMantineReactTable } from "@homarr/ui/hooks";
|
|||||||
|
|
||||||
interface UserListComponentProps {
|
interface UserListComponentProps {
|
||||||
initialUserList: RouterOutputs["user"]["getAll"];
|
initialUserList: RouterOutputs["user"]["getAll"];
|
||||||
|
credentialsProviderEnabled: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const UserListComponent = ({ initialUserList }: UserListComponentProps) => {
|
export const UserListComponent = ({ initialUserList, credentialsProviderEnabled }: UserListComponentProps) => {
|
||||||
const tUserList = useScopedI18n("management.page.user.list");
|
const tUserList = useScopedI18n("management.page.user.list");
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const { data, isLoading } = clientApi.user.getAll.useQuery(undefined, {
|
const { data, isLoading } = clientApi.user.getAll.useQuery(undefined, {
|
||||||
@@ -68,11 +69,12 @@ export const UserListComponent = ({ initialUserList }: UserListComponentProps) =
|
|||||||
enableFullScreenToggle: false,
|
enableFullScreenToggle: false,
|
||||||
layoutMode: "grid-no-grow",
|
layoutMode: "grid-no-grow",
|
||||||
getRowId: (row) => row.id,
|
getRowId: (row) => row.id,
|
||||||
renderTopToolbarCustomActions: () => (
|
renderTopToolbarCustomActions: () =>
|
||||||
<Button component={Link} href="/manage/users/create">
|
credentialsProviderEnabled ? (
|
||||||
Create New User
|
<Button component={Link} href="/manage/users/create">
|
||||||
</Button>
|
{t("management.page.user.create.title")}
|
||||||
),
|
</Button>
|
||||||
|
) : null,
|
||||||
state: {
|
state: {
|
||||||
isLoading,
|
isLoading,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import { notFound } from "next/navigation";
|
||||||
|
|
||||||
|
import { isProviderEnabled } from "@homarr/auth/server";
|
||||||
import { getScopedI18n } from "@homarr/translation/server";
|
import { getScopedI18n } from "@homarr/translation/server";
|
||||||
|
|
||||||
import { DynamicBreadcrumb } from "~/components/navigation/dynamic-breadcrumb";
|
import { DynamicBreadcrumb } from "~/components/navigation/dynamic-breadcrumb";
|
||||||
@@ -5,6 +8,8 @@ import { createMetaTitle } from "~/metadata";
|
|||||||
import { UserCreateStepperComponent } from "./_components/create-user-stepper";
|
import { UserCreateStepperComponent } from "./_components/create-user-stepper";
|
||||||
|
|
||||||
export async function generateMetadata() {
|
export async function generateMetadata() {
|
||||||
|
if (!isProviderEnabled("credentials")) return {};
|
||||||
|
|
||||||
const t = await getScopedI18n("management.page.user.create");
|
const t = await getScopedI18n("management.page.user.create");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -13,6 +18,10 @@ export async function generateMetadata() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function CreateUserPage() {
|
export default function CreateUserPage() {
|
||||||
|
if (!isProviderEnabled("credentials")) {
|
||||||
|
notFound();
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DynamicBreadcrumb />
|
<DynamicBreadcrumb />
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { api } from "@homarr/api/server";
|
import { api } from "@homarr/api/server";
|
||||||
|
import { isProviderEnabled } from "@homarr/auth/server";
|
||||||
import { getScopedI18n } from "@homarr/translation/server";
|
import { getScopedI18n } from "@homarr/translation/server";
|
||||||
|
|
||||||
import { DynamicBreadcrumb } from "~/components/navigation/dynamic-breadcrumb";
|
import { DynamicBreadcrumb } from "~/components/navigation/dynamic-breadcrumb";
|
||||||
@@ -15,10 +16,12 @@ export async function generateMetadata() {
|
|||||||
|
|
||||||
export default async function UsersPage() {
|
export default async function UsersPage() {
|
||||||
const userList = await api.user.getAll();
|
const userList = await api.user.getAll();
|
||||||
|
const credentialsProviderEnabled = isProviderEnabled("credentials");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DynamicBreadcrumb />
|
<DynamicBreadcrumb />
|
||||||
<UserListComponent initialUserList={userList} />
|
<UserListComponent initialUserList={userList} credentialsProviderEnabled={credentialsProviderEnabled} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user