search user

This commit is contained in:
peintnermax
2024-08-21 11:18:12 +02:00
parent 6b5069d38e
commit bcab9bebd0
2 changed files with 41 additions and 32 deletions

View File

@@ -4,6 +4,7 @@ import {
createUser, createUser,
getBrandingSettings, getBrandingSettings,
getIDPByID, getIDPByID,
listUsers,
retrieveIDPIntent, retrieveIDPIntent,
} from "@/lib/zitadel"; } from "@/lib/zitadel";
import Alert, { AlertType } from "@/ui/Alert"; import Alert, { AlertType } from "@/ui/Alert";
@@ -152,39 +153,47 @@ export default async function Page({
if (options?.isLinkingAllowed) { if (options?.isLinkingAllowed) {
const userId = ""; const userId = "";
const idpLink = await addIDPLink( const foundUser = await listUsers(idpInformation.userName).then(
{ (response) => {
id: idpInformation.idpId, return response.result ? response.result[0] : null;
userId: idpInformation.userId,
userName: idpInformation.userName,
}, },
userId, );
).catch((error) => {
return (
<DynamicTheme branding={branding}>
<div className="flex flex-col items-center space-y-4">
<h1>Linking failed</h1>
<div className="w-full">
{
<Alert type={AlertType.ALERT}>
{JSON.stringify(error.message)}
</Alert>
}
</div>
</div>
</DynamicTheme>
);
});
if (idpLink) { if (foundUser) {
return ( const idpLink = await addIDPLink(
<DynamicTheme branding={branding}> {
<div className="flex flex-col items-center space-y-4"> id: idpInformation.idpId,
<h1>Account successfully linked</h1> userId: idpInformation.userId,
<div>Your account has successfully been linked!</div> userName: idpInformation.userName,
</div> },
</DynamicTheme> userId,
); ).catch((error) => {
return (
<DynamicTheme branding={branding}>
<div className="flex flex-col items-center space-y-4">
<h1>Linking failed</h1>
<div className="w-full">
{
<Alert type={AlertType.ALERT}>
{JSON.stringify(error.message)}
</Alert>
}
</div>
</div>
</DynamicTheme>
);
});
if (idpLink) {
return (
<DynamicTheme branding={branding}>
<div className="flex flex-col items-center space-y-4">
<h1>Account successfully linked</h1>
<div>Your account has successfully been linked!</div>
</div>
</DynamicTheme>
);
}
} }
} else if (options?.isCreationAllowed && options.isAutoCreation) { } else if (options?.isCreationAllowed && options.isAutoCreation) {
const userId = await createUser(provider, idpInformation).catch( const userId = await createUser(provider, idpInformation).catch(

View File

@@ -237,7 +237,7 @@ export async function getUserByID(userId: string) {
return userService.getUserByID({ userId }, {}); return userService.getUserByID({ userId }, {});
} }
export async function listUsers(userName: string, organizationId: string) { export async function listUsers(userName: string, organizationId?: string) {
return userService.listUsers( return userService.listUsers(
{ {
queries: organizationId queries: organizationId