mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 10:04:25 +00:00
org filter
This commit is contained in:
@@ -8,9 +8,10 @@ export default async function Page({
|
|||||||
}) {
|
}) {
|
||||||
const loginName = searchParams?.loginName;
|
const loginName = searchParams?.loginName;
|
||||||
const authRequestId = searchParams?.authRequestId;
|
const authRequestId = searchParams?.authRequestId;
|
||||||
|
const organization = searchParams?.organization;
|
||||||
const submit: boolean = searchParams?.submit === "true";
|
const submit: boolean = searchParams?.submit === "true";
|
||||||
|
|
||||||
const loginSettings = await getLoginSettings(server);
|
const loginSettings = await getLoginSettings(server, organization);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-center space-y-4">
|
<div className="flex flex-col items-center space-y-4">
|
||||||
@@ -21,6 +22,7 @@ export default async function Page({
|
|||||||
loginSettings={loginSettings}
|
loginSettings={loginSettings}
|
||||||
loginName={loginName}
|
loginName={loginName}
|
||||||
authRequestId={authRequestId}
|
authRequestId={authRequestId}
|
||||||
|
organization={organization}
|
||||||
submit={submit}
|
submit={submit}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
import { listAuthenticationMethodTypes } from "#/lib/zitadel";
|
import { listAuthenticationMethodTypes, listUsers } from "#/lib/zitadel";
|
||||||
import { createSessionAndUpdateCookie } from "#/utils/session";
|
import { createSessionAndUpdateCookie } from "#/utils/session";
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
|
||||||
export async function POST(request: NextRequest) {
|
export async function POST(request: NextRequest) {
|
||||||
const body = await request.json();
|
const body = await request.json();
|
||||||
if (body) {
|
if (body) {
|
||||||
const { loginName, authRequestId } = body;
|
const { loginName, authRequestId, organization } = body;
|
||||||
|
// TODO - search for users with org
|
||||||
|
// return listUsers(loginName).then((users) => {
|
||||||
|
// if (users.details && users.details.totalResult == 1) {
|
||||||
|
// }
|
||||||
return createSessionAndUpdateCookie(
|
return createSessionAndUpdateCookie(
|
||||||
loginName,
|
loginName,
|
||||||
undefined,
|
undefined,
|
||||||
@@ -33,6 +36,7 @@ export async function POST(request: NextRequest) {
|
|||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
return NextResponse.json(error, { status: 500 });
|
return NextResponse.json(error, { status: 500 });
|
||||||
});
|
});
|
||||||
|
// });
|
||||||
} else {
|
} else {
|
||||||
return NextResponse.error();
|
return NextResponse.error();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import {
|
|||||||
VerifyEmailResponse,
|
VerifyEmailResponse,
|
||||||
SetSessionResponse,
|
SetSessionResponse,
|
||||||
SetSessionRequest,
|
SetSessionRequest,
|
||||||
|
ListUsersResponse,
|
||||||
|
ListUsersRequest,
|
||||||
DeleteSessionResponse,
|
DeleteSessionResponse,
|
||||||
VerifyPasskeyRegistrationResponse,
|
VerifyPasskeyRegistrationResponse,
|
||||||
LoginSettings,
|
LoginSettings,
|
||||||
@@ -35,6 +37,7 @@ import {
|
|||||||
CreateCallbackRequest,
|
CreateCallbackRequest,
|
||||||
CreateCallbackResponse,
|
CreateCallbackResponse,
|
||||||
RequestChallenges,
|
RequestChallenges,
|
||||||
|
TextQueryMethod,
|
||||||
AddHumanUserRequest,
|
AddHumanUserRequest,
|
||||||
} from "@zitadel/server";
|
} from "@zitadel/server";
|
||||||
|
|
||||||
@@ -61,11 +64,12 @@ export async function getBrandingSettings(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getLoginSettings(
|
export async function getLoginSettings(
|
||||||
server: ZitadelServer
|
server: ZitadelServer,
|
||||||
|
orgId?: string
|
||||||
): Promise<LoginSettings | undefined> {
|
): Promise<LoginSettings | undefined> {
|
||||||
const settingsService = settings.getSettings(server);
|
const settingsService = settings.getSettings(server);
|
||||||
return settingsService
|
return settingsService
|
||||||
.getLoginSettings({}, {})
|
.getLoginSettings({ ctx: orgId ? { orgId } : { instance: true } }, {})
|
||||||
.then((resp: GetLoginSettingsResponse) => resp.settings);
|
.then((resp: GetLoginSettingsResponse) => resp.settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,6 +215,25 @@ export async function addHumanUser(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function listUsers(userName: string): Promise<ListUsersResponse> {
|
||||||
|
// TODO limit for organization
|
||||||
|
const userService = user.getUser(server);
|
||||||
|
|
||||||
|
return userService.listUsers(
|
||||||
|
{
|
||||||
|
queries: [
|
||||||
|
{
|
||||||
|
userNameQuery: {
|
||||||
|
userName,
|
||||||
|
method: TextQueryMethod.TEXT_QUERY_METHOD_EQUALS,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export async function startIdentityProviderFlow(
|
export async function startIdentityProviderFlow(
|
||||||
server: ZitadelServer,
|
server: ZitadelServer,
|
||||||
{ idpId, urls }: StartIdentityProviderIntentRequest
|
{ idpId, urls }: StartIdentityProviderIntentRequest
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Button, ButtonVariants } from "./Button";
|
import { Button, ButtonVariants } from "./Button";
|
||||||
import { TextInput } from "./Input";
|
import { TextInput } from "./Input";
|
||||||
import { useForm } from "react-hook-form";
|
import { SubmitHandler, useForm } from "react-hook-form";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { Spinner } from "./Spinner";
|
import { Spinner } from "./Spinner";
|
||||||
import { LoginSettings } from "@zitadel/server";
|
import { LoginSettings } from "@zitadel/server";
|
||||||
@@ -17,6 +17,7 @@ type Props = {
|
|||||||
loginSettings: LoginSettings | undefined;
|
loginSettings: LoginSettings | undefined;
|
||||||
loginName: string | undefined;
|
loginName: string | undefined;
|
||||||
authRequestId: string | undefined;
|
authRequestId: string | undefined;
|
||||||
|
organization?: string;
|
||||||
submit: boolean;
|
submit: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -24,6 +25,7 @@ export default function UsernameForm({
|
|||||||
loginSettings,
|
loginSettings,
|
||||||
loginName,
|
loginName,
|
||||||
authRequestId,
|
authRequestId,
|
||||||
|
organization,
|
||||||
submit,
|
submit,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const { register, handleSubmit, formState } = useForm<Inputs>({
|
const { register, handleSubmit, formState } = useForm<Inputs>({
|
||||||
@@ -38,13 +40,17 @@ export default function UsernameForm({
|
|||||||
const [loading, setLoading] = useState<boolean>(false);
|
const [loading, setLoading] = useState<boolean>(false);
|
||||||
const [error, setError] = useState<string>("");
|
const [error, setError] = useState<string>("");
|
||||||
|
|
||||||
async function submitLoginName(values: Inputs) {
|
async function submitLoginName(values: Inputs, organization?: string) {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
const body = {
|
let body: any = {
|
||||||
loginName: values.loginName,
|
loginName: values.loginName,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (organization) {
|
||||||
|
body.organization = organization;
|
||||||
|
}
|
||||||
|
|
||||||
const res = await fetch("/api/loginname", {
|
const res = await fetch("/api/loginname", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -63,8 +69,11 @@ export default function UsernameForm({
|
|||||||
return res.json();
|
return res.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setLoginNameAndGetAuthMethods(values: Inputs) {
|
function setLoginNameAndGetAuthMethods(
|
||||||
return submitLoginName(values).then((response) => {
|
values: Inputs,
|
||||||
|
organization?: string
|
||||||
|
) {
|
||||||
|
return submitLoginName(values, organization).then((response) => {
|
||||||
if (response.authMethodTypes.length == 1) {
|
if (response.authMethodTypes.length == 1) {
|
||||||
const method = response.authMethodTypes[0];
|
const method = response.authMethodTypes[0];
|
||||||
switch (method) {
|
switch (method) {
|
||||||
@@ -152,7 +161,7 @@ export default function UsernameForm({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (submit && loginName) {
|
if (submit && loginName) {
|
||||||
// When we navigate to this page, we always want to be redirected if submit is true and the parameters are valid.
|
// When we navigate to this page, we always want to be redirected if submit is true and the parameters are valid.
|
||||||
setLoginNameAndGetAuthMethods({ loginName });
|
setLoginNameAndGetAuthMethods({ loginName }, organization);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -180,7 +189,9 @@ export default function UsernameForm({
|
|||||||
className="self-end"
|
className="self-end"
|
||||||
variant={ButtonVariants.Primary}
|
variant={ButtonVariants.Primary}
|
||||||
disabled={loading || !formState.isValid}
|
disabled={loading || !formState.isValid}
|
||||||
onClick={handleSubmit(setLoginNameAndGetAuthMethods)}
|
onClick={handleSubmit((e) =>
|
||||||
|
setLoginNameAndGetAuthMethods(e, organization)
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
{loading && <Spinner className="h-5 w-5 mr-2" />}
|
{loading && <Spinner className="h-5 w-5 mr-2" />}
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ export {
|
|||||||
GetActiveIdentityProvidersResponse,
|
GetActiveIdentityProvidersResponse,
|
||||||
GetActiveIdentityProvidersRequest,
|
GetActiveIdentityProvidersRequest,
|
||||||
} from "./proto/server/zitadel/settings/v2beta/settings_service";
|
} from "./proto/server/zitadel/settings/v2beta/settings_service";
|
||||||
|
export { TextQueryMethod } from "./proto/server/zitadel/object/v2beta/object";
|
||||||
export {
|
export {
|
||||||
AddHumanUserResponse,
|
AddHumanUserResponse,
|
||||||
AddHumanUserRequest,
|
AddHumanUserRequest,
|
||||||
@@ -80,6 +81,8 @@ export {
|
|||||||
StartIdentityProviderIntentResponse,
|
StartIdentityProviderIntentResponse,
|
||||||
RetrieveIdentityProviderIntentRequest,
|
RetrieveIdentityProviderIntentRequest,
|
||||||
RetrieveIdentityProviderIntentResponse,
|
RetrieveIdentityProviderIntentResponse,
|
||||||
|
ListUsersRequest,
|
||||||
|
ListUsersResponse,
|
||||||
} from "./proto/server/zitadel/user/v2beta/user_service";
|
} from "./proto/server/zitadel/user/v2beta/user_service";
|
||||||
export {
|
export {
|
||||||
SetHumanPasswordResponse,
|
SetHumanPasswordResponse,
|
||||||
|
|||||||
Reference in New Issue
Block a user