Skip to content

Commit

Permalink
Merge pull request #1 from yordis/remove-unnecessary-changes
Browse files Browse the repository at this point in the history
Remove unnecessary changes
  • Loading branch information
yordis authored Jun 4, 2024
2 parents a8829ed + 89671e1 commit 97c500d
Show file tree
Hide file tree
Showing 48 changed files with 1,443 additions and 892 deletions.
4 changes: 3 additions & 1 deletion apps/login/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"build": "next build",
"prestart": "pnpm build",
"start": "next start",
"clean": "pnpm mock:destroy && rm -rf .turbo && rm -rf node_modules && rm -rf .next"
"clean": "pnpm mock:destroy && rm -rf .turbo && rm -rf node_modules && rm -rf .next",
"format": "prettier --write \"**/*.{ts,tsx,md}\""
},
"git": {
"pre-commit": "lint-staged"
Expand All @@ -39,6 +40,7 @@
"@zitadel/proto": "workspace:*",
"@zitadel/client2": "workspace:*",
"@zitadel/react": "workspace:*",
"@zitadel/node": "workspace:*",
"clsx": "1.2.1",
"copy-to-clipboard": "^3.3.3",
"moment": "^2.29.4",
Expand Down
26 changes: 9 additions & 17 deletions apps/login/src/app/(login)/accounts/page.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
import { Session } from "@zitadel/proto/zitadel/session/v2beta/session_pb";
import { getBrandingSettings, sessionService } from "@/lib/zitadel";
import { getBrandingSettings, listSessions } from "@/lib/zitadel";
import { getAllSessionCookieIds } from "@/utils/cookies";
import { UserPlusIcon } from "@heroicons/react/24/outline";
import Link from "next/link";
import SessionsList from "@/ui/SessionsList";
import DynamicTheme from "@/ui/DynamicTheme";

async function loadSessions(): Promise<Session[]> {
async function loadSessions() {
const ids = await getAllSessionCookieIds();

if (ids.length === 0) {
if (ids && ids.length) {
const response = await listSessions(
ids.filter((id: string | undefined) => !!id),
);
return response?.sessions ?? [];
} else {
console.info("No session cookie found.");
return [];
}

const response = await sessionService.listSessions({
queries: [
{
query: {
case: "idsQuery",
value: { ids: ids.filter((id: string | undefined) => !!id) },
},
},
],
});

return response.sessions;
}

export default async function Page({
Expand Down
14 changes: 8 additions & 6 deletions apps/login/src/app/(login)/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

import { Boundary } from "@/ui/Boundary";
import { Button } from "@/ui/Button";
import React from "react";

export default function Error({ error, reset }: any) {
React.useEffect(() => {
console.log("logging error:", error);
}, [error]);

export default function Error(props: {
error: Error | null;
reset: () => void;
}) {
return (
<Boundary labels={["Login Error"]} color="red">
<div className="space-y-4">
<div className="text-sm text-red-500 dark:text-red-500">
<strong className="font-bold">Error:</strong> {props.error?.message}
<strong className="font-bold">Error:</strong> {error?.message}
</div>
<div>
<Button onClick={props.reset}>Try Again</Button>
<Button onClick={() => reset()}>Try Again</Button>
</div>
</div>
</Boundary>
Expand Down
27 changes: 16 additions & 11 deletions apps/login/src/app/(login)/idp/[provider]/success/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { getBrandingSettings, userService } from "@/lib/zitadel";
import Alert, { AlertType } from "@/ui/Alert";
import DynamicTheme from "@/ui/DynamicTheme";
import IdpSignin from "@/ui/IdpSignin";
import { PartialMessage } from "@zitadel/client2";
import { AddHumanUserRequest } from "@zitadel/proto/zitadel/user/v2beta/user_service_pb";
import {
IDPInformation,
IDPLink,
} from "@zitadel/proto/zitadel/user/v2beta/idp_pb";
import { AddHumanUserRequest } from "@zitadel/proto/zitadel/user/v2beta/user_service_pb";
import { PartialMessage } from "@zitadel/client2";

const PROVIDER_MAPPING: {
[provider: string]: (
Expand All @@ -34,7 +34,7 @@ const PROVIDER_MAPPING: {
const req: PartialMessage<AddHumanUserRequest> = {
username: idp.userName,
email: {
email: rawInfo.User.email,
email: rawInfo.User?.email,
verification: { case: "isVerified", value: true },
},
// organisation: Organisation | undefined;
Expand All @@ -60,14 +60,14 @@ const PROVIDER_MAPPING: {
const req: PartialMessage<AddHumanUserRequest> = {
username: idp.userName,
email: {
email: rawInfo.email,
email: rawInfo?.email,
verification: { case: "isVerified", value: true },
},
// organisation: Organisation | undefined;
profile: {
displayName: rawInfo.name ?? "",
givenName: rawInfo.name ?? "",
familyName: rawInfo.name ?? "",
displayName: rawInfo?.name ?? "",
givenName: rawInfo?.name ?? "",
familyName: rawInfo?.name ?? "",
},
idpLinks: [idpLink],
};
Expand Down Expand Up @@ -106,6 +106,7 @@ export default async function Page({
return retrieveIDPIntent(id, token)
.then((resp) => {
const { idpInformation, userId } = resp;

if (idpInformation) {
// handle login
if (userId) {
Expand Down Expand Up @@ -175,10 +176,14 @@ export default async function Page({
});
} else {
return (
<div className="flex flex-col items-center space-y-4">
<h1>Register</h1>
<p className="ztdl-p">No id and token received!</p>
</div>
<DynamicTheme branding={branding}>
<div className="flex flex-col items-center space-y-4">
<div className="flex flex-col items-center space-y-4">
<h1>Register</h1>
<p className="ztdl-p">No id and token received!</p>
</div>
</div>
</DynamicTheme>
);
}
}
12 changes: 4 additions & 8 deletions apps/login/src/app/(login)/idp/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ import {
import DynamicTheme from "@/ui/DynamicTheme";
import { SignInWithIDP } from "@/ui/SignInWithIDP";
import { makeReqCtx } from "@zitadel/client2/v2beta";
import { IdentityProvider } from "@zitadel/proto/zitadel/settings/v2beta/login_settings_pb";
import { GetActiveIdentityProvidersResponse } from "@zitadel/proto/zitadel/settings/v2beta/settings_service_pb";

function getIdentityProviders(
orgId?: string,
): Promise<IdentityProvider[] | undefined> {
function getIdentityProviders(orgId?: string) {
return settingsService
.getActiveIdentityProviders({ ctx: makeReqCtx(orgId) })
.then((resp: GetActiveIdentityProvidersResponse) => {
.getActiveIdentityProviders({ ctx: makeReqCtx(orgId) }, {})
.then((resp) => {
return resp.identityProviders;
});
}
Expand Down Expand Up @@ -51,7 +47,7 @@ export default async function Page({
identityProviders={identityProviders}
authRequestId={authRequestId}
organization={organization}
/>
></SignInWithIDP>
)}
</div>
</DynamicTheme>
Expand Down
24 changes: 18 additions & 6 deletions apps/login/src/app/(login)/loginname/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,34 @@ import {
getBrandingSettings,
getLegalAndSupportSettings,
getLoginSettings,
getIdentityProviders,
settingsService,
} from "@/lib/zitadel";
import DynamicTheme from "@/ui/DynamicTheme";
import { SignInWithIDP } from "@/ui/SignInWithIDP";
import UsernameForm from "@/ui/UsernameForm";
import { makeReqCtx } from "@zitadel/client2/v2beta";

export default async function Page(props: {
function getIdentityProviders(orgId?: string) {
return settingsService
.getActiveIdentityProviders({ ctx: makeReqCtx(orgId) }, {})
.then((resp) => {
return resp.identityProviders;
});
}

export default async function Page({
searchParams,
}: {
searchParams: Record<string | number | symbol, string | undefined>;
}) {
const loginName = props.searchParams?.loginName;
const authRequestId = props.searchParams?.authRequestId;
const organization = props.searchParams?.organization;
const submit: boolean = props.searchParams?.submit === "true";
const loginName = searchParams?.loginName;
const authRequestId = searchParams?.authRequestId;
const organization = searchParams?.organization;
const submit: boolean = searchParams?.submit === "true";

const loginSettings = await getLoginSettings(organization);
const legal = await getLegalAndSupportSettings();

const identityProviders = await getIdentityProviders(organization);

const host = process.env.VERCEL_URL
Expand Down
102 changes: 100 additions & 2 deletions apps/login/src/app/(login)/mfa/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,101 @@
export default function Page() {
return <div className="flex flex-col items-center space-y-4">mfa</div>;
import {
getBrandingSettings,
getSession,
listAuthenticationMethodTypes,
} from "@/lib/zitadel";
import Alert from "@/ui/Alert";
import ChooseSecondFactor from "@/ui/ChooseSecondFactor";
import DynamicTheme from "@/ui/DynamicTheme";
import UserAvatar from "@/ui/UserAvatar";
import {
getMostRecentCookieWithLoginname,
getSessionCookieById,
} from "@/utils/cookies";

export default async function Page({
searchParams,
}: {
searchParams: Record<string | number | symbol, string | undefined>;
}) {
const { loginName, checkAfter, authRequestId, organization, sessionId } =
searchParams;

const sessionFactors = sessionId
? await loadSessionById(sessionId, organization)
: await loadSessionByLoginname(loginName, organization);

async function loadSessionByLoginname(
loginName?: string,
organization?: string,
) {
const recent = await getMostRecentCookieWithLoginname(
loginName,
organization,
);
return getSession(recent.id, recent.token).then((response) => {
if (response?.session && response.session.factors?.user?.id) {
return listAuthenticationMethodTypes(
response.session.factors.user.id,
).then((methods) => {
return {
factors: response.session?.factors,
authMethods: methods.authMethodTypes ?? [],
};
});
}
});
}

async function loadSessionById(sessionId: string, organization?: string) {
const recent = await getSessionCookieById(sessionId, organization);
return getSession(recent.id, recent.token).then((response) => {
if (response?.session && response.session.factors?.user?.id) {
return listAuthenticationMethodTypes(
response.session.factors.user.id,
).then((methods) => {
return {
factors: response.session?.factors,
authMethods: methods.authMethodTypes ?? [],
};
});
}
});
}

const branding = await getBrandingSettings(organization);

return (
<DynamicTheme branding={branding}>
<div className="flex flex-col items-center space-y-4">
<h1>Verify 2-Factor</h1>

<p className="ztdl-p">Choose one of the following second factors.</p>

{sessionFactors && (
<UserAvatar
loginName={loginName ?? sessionFactors.factors?.user?.loginName}
displayName={sessionFactors.factors?.user?.displayName}
showDropdown
searchParams={searchParams}
></UserAvatar>
)}

{!(loginName || sessionId) && (
<Alert>Provide your active session as loginName param</Alert>
)}

{sessionFactors ? (
<ChooseSecondFactor
loginName={loginName}
sessionId={sessionId}
authRequestId={authRequestId}
organization={organization}
userMethods={sessionFactors.authMethods ?? []}
></ChooseSecondFactor>
) : (
<Alert>No second factors available to setup.</Alert>
)}
</div>
</DynamicTheme>
);
}
Loading

0 comments on commit 97c500d

Please sign in to comment.