Skip to content

Commit

Permalink
chore: revert changes batch 2
Browse files Browse the repository at this point in the history
  • Loading branch information
yordis committed Jun 4, 2024
1 parent 13c78a0 commit 89671e1
Show file tree
Hide file tree
Showing 51 changed files with 417 additions and 487 deletions.
3 changes: 2 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 Down
14 changes: 2 additions & 12 deletions apps/login/src/app/(login)/idp/[provider]/failure/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import { ProviderSlug } from "@/lib/demos";
import { getBrandingSettings, server } from "@/lib/zitadel";
import Alert, { AlertType } from "@/ui/Alert";
import { getBrandingSettings } from "@/lib/zitadel";
import DynamicTheme from "@/ui/DynamicTheme";
import IdpSignin from "@/ui/IdpSignin";
import {
AddHumanUserRequest,
IDPInformation,
RetrieveIdentityProviderIntentResponse,
user,
IDPLink,
} from "@zitadel/server";
import { ClientError } from "nice-grpc";

const PROVIDER_NAME_MAPPING: {
[provider: string]: string;
Expand All @@ -29,7 +19,7 @@ export default async function Page({
const { id, token, authRequestId, organization } = searchParams;
const { provider } = params;

const branding = await getBrandingSettings(server, organization);
const branding = await getBrandingSettings(organization);

if (provider) {
return (
Expand Down
20 changes: 11 additions & 9 deletions apps/login/src/app/(login)/idp/[provider]/success/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { ProviderSlug } from "@/lib/demos";
import {getBrandingSettings, userService} from "@/lib/zitadel";
import { getBrandingSettings, userService } from "@/lib/zitadel";
import Alert, { AlertType } from "@/ui/Alert";
import DynamicTheme from "@/ui/DynamicTheme";
import IdpSignin from "@/ui/IdpSignin";
import {AddHumanUserRequest} from "@zitadel/proto/zitadel/user/v2beta/user_service_pb";
import {IDPInformation, IDPLink} from "@zitadel/proto/zitadel/user/v2beta/idp_pb";
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 { PartialMessage } from "@zitadel/client2";

const PROVIDER_MAPPING: {
[provider: string]: (rI: IDPInformation) => PartialMessage<AddHumanUserRequest>;
[provider: string]: (
rI: IDPInformation,
) => PartialMessage<AddHumanUserRequest>;
} = {
[ProviderSlug.GOOGLE]: (idp: IDPInformation) => {
const rawInfo = idp.rawInformation?.toJson() as {
Expand Down Expand Up @@ -70,10 +75,7 @@ const PROVIDER_MAPPING: {
},
};

function retrieveIDPIntent(
id: string,
token: string,
) {
function retrieveIDPIntent(id: string, token: string) {
return userService.retrieveIdentityProviderIntent(
{ idpIntentId: id, idpIntentToken: token },
{},
Expand Down
28 changes: 8 additions & 20 deletions apps/login/src/app/(login)/idp/page.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
import {
getBrandingSettings,
getLegalAndSupportSettings,
server,
settingsService,
} from "@/lib/zitadel";
import DynamicTheme from "@/ui/DynamicTheme";
import { SignInWithIDP } from "@/ui/SignInWithIDP";
import {
GetActiveIdentityProvidersResponse,
IdentityProvider,
ZitadelServer,
settings,
} from "@zitadel/server";
import { makeReqCtx } from "@zitadel/client2/v2beta";

function getIdentityProviders(
server: ZitadelServer,
orgId?: string,
): Promise<IdentityProvider[] | undefined> {
const settingsService = settings.getSettings(server);
function getIdentityProviders(orgId?: string) {
return settingsService
.getActiveIdentityProviders(
orgId ? { ctx: { orgId } } : { ctx: { instance: true } },
{},
)
.then((resp: GetActiveIdentityProvidersResponse) => {
.getActiveIdentityProviders({ ctx: makeReqCtx(orgId) }, {})
.then((resp) => {
return resp.identityProviders;
});
}
Expand All @@ -35,15 +23,15 @@ export default async function Page({
const authRequestId = searchParams?.authRequestId;
const organization = searchParams?.organization;

const legal = await getLegalAndSupportSettings(server, organization);
const legal = await getLegalAndSupportSettings(organization);

const identityProviders = await getIdentityProviders(server, organization);
const identityProviders = await getIdentityProviders(organization);

const host = process.env.VERCEL_URL
? `https://${process.env.VERCEL_URL}`
: "http://localhost:3000";

const branding = await getBrandingSettings(server, organization);
const branding = await getBrandingSettings(organization);

return (
<DynamicTheme branding={branding}>
Expand Down
30 changes: 9 additions & 21 deletions apps/login/src/app/(login)/loginname/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,17 @@ import {
getBrandingSettings,
getLegalAndSupportSettings,
getLoginSettings,
server,
settingsService,
} from "@/lib/zitadel";
import DynamicTheme from "@/ui/DynamicTheme";
import { SignInWithIDP } from "@/ui/SignInWithIDP";
import UsernameForm from "@/ui/UsernameForm";
import {
GetActiveIdentityProvidersResponse,
IdentityProvider,
ZitadelServer,
settings,
} from "@zitadel/server";
import { makeReqCtx } from "@zitadel/client2/v2beta";

function getIdentityProviders(
server: ZitadelServer,
orgId?: string,
): Promise<IdentityProvider[] | undefined> {
const settingsService = settings.getSettings(server);
function getIdentityProviders(orgId?: string) {
return settingsService
.getActiveIdentityProviders(
orgId ? { ctx: { orgId } } : { ctx: { instance: true } },
{},
)
.then((resp: GetActiveIdentityProvidersResponse) => {
.getActiveIdentityProviders({ ctx: makeReqCtx(orgId) }, {})
.then((resp) => {
return resp.identityProviders;
});
}
Expand All @@ -39,16 +27,16 @@ export default async function Page({
const organization = searchParams?.organization;
const submit: boolean = searchParams?.submit === "true";

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

const identityProviders = await getIdentityProviders(server, organization);
const identityProviders = await getIdentityProviders(organization);

const host = process.env.VERCEL_URL
? `https://${process.env.VERCEL_URL}`
: "http://localhost:3000";

const branding = await getBrandingSettings(server, organization);
const branding = await getBrandingSettings(organization);

return (
<DynamicTheme branding={branding}>
Expand Down
7 changes: 3 additions & 4 deletions apps/login/src/app/(login)/mfa/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
getBrandingSettings,
getSession,
listAuthenticationMethodTypes,
server,
} from "@/lib/zitadel";
import Alert from "@/ui/Alert";
import ChooseSecondFactor from "@/ui/ChooseSecondFactor";
Expand Down Expand Up @@ -33,7 +32,7 @@ export default async function Page({
loginName,
organization,
);
return getSession(server, recent.id, recent.token).then((response) => {
return getSession(recent.id, recent.token).then((response) => {
if (response?.session && response.session.factors?.user?.id) {
return listAuthenticationMethodTypes(
response.session.factors.user.id,
Expand All @@ -49,7 +48,7 @@ export default async function Page({

async function loadSessionById(sessionId: string, organization?: string) {
const recent = await getSessionCookieById(sessionId, organization);
return getSession(server, recent.id, recent.token).then((response) => {
return getSession(recent.id, recent.token).then((response) => {
if (response?.session && response.session.factors?.user?.id) {
return listAuthenticationMethodTypes(
response.session.factors.user.id,
Expand All @@ -63,7 +62,7 @@ export default async function Page({
});
}

const branding = await getBrandingSettings(server, organization);
const branding = await getBrandingSettings(organization);

return (
<DynamicTheme branding={branding}>
Expand Down
27 changes: 17 additions & 10 deletions apps/login/src/app/(login)/mfa/set/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
getSession,
getUserByID,
listAuthenticationMethodTypes,
server,
} from "@/lib/zitadel";
import Alert from "@/ui/Alert";
import ChooseSecondFactorToSetup from "@/ui/ChooseSecondFactorToSetup";
Expand All @@ -14,7 +13,6 @@ import {
getMostRecentCookieWithLoginname,
getSessionCookieById,
} from "@/utils/cookies";
import { user } from "@zitadel/server";

export default async function Page({
searchParams,
Expand All @@ -36,16 +34,21 @@ export default async function Page({
loginName,
organization,
);
return getSession(server, recent.id, recent.token).then((response) => {
return getSession(recent.id, recent.token).then((response) => {
if (response?.session && response.session.factors?.user?.id) {
const userId = response.session.factors.user.id;
return listAuthenticationMethodTypes(userId).then((methods) => {
return getUserByID(userId).then((user) => {
const humanUser =
user.user?.type.case === "human"
? user.user?.type.value
: undefined;

return {
factors: response.session?.factors,
authMethods: methods.authMethodTypes ?? [],
phoneVerified: user.user?.human?.phone?.isVerified ?? false,
emailVerified: user.user?.human?.email?.isVerified ?? false,
phoneVerified: humanUser?.phone?.isVerified ?? false,
emailVerified: humanUser?.email?.isVerified ?? false,
};
});
});
Expand All @@ -55,25 +58,29 @@ export default async function Page({

async function loadSessionById(sessionId: string, organization?: string) {
const recent = await getSessionCookieById(sessionId, organization);
return getSession(server, recent.id, recent.token).then((response) => {
return getSession(recent.id, recent.token).then((response) => {
if (response?.session && response.session.factors?.user?.id) {
const userId = response.session.factors.user.id;
return listAuthenticationMethodTypes(userId).then((methods) => {
return getUserByID(userId).then((user) => {
const humanUser =
user.user?.type.case === "human"
? user.user?.type.value
: undefined;
return {
factors: response.session?.factors,
authMethods: methods.authMethodTypes ?? [],
phoneVerified: user.user?.human?.phone?.isVerified ?? false,
emailVerified: user.user?.human?.email?.isVerified ?? false,
phoneVerified: humanUser?.phone?.isVerified ?? false,
emailVerified: humanUser?.email?.isVerified ?? false,
};
});
});
}
});
}

const branding = await getBrandingSettings(server, organization);
const loginSettings = await getLoginSettings(server, organization);
const branding = await getBrandingSettings(organization);
const loginSettings = await getLoginSettings(organization);

return (
<DynamicTheme branding={branding}>
Expand Down
5 changes: 2 additions & 3 deletions apps/login/src/app/(login)/otp/[method]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
getBrandingSettings,
getLoginSettings,
getSession,
server,
} from "@/lib/zitadel";
import Alert from "@/ui/Alert";
import DynamicTheme from "@/ui/DynamicTheme";
Expand All @@ -24,15 +23,15 @@ export default async function Page({

const { session, token } = await loadSession(loginName, organization);

const branding = await getBrandingSettings(server, organization);
const branding = await getBrandingSettings(organization);

async function loadSession(loginName?: string, organization?: string) {
const recent = await getMostRecentCookieWithLoginname(
loginName,
organization,
);

return getSession(server, recent.id, recent.token).then((response) => {
return getSession(recent.id, recent.token).then((response) => {
return { session: response?.session, token: recent.token };
});
}
Expand Down
12 changes: 5 additions & 7 deletions apps/login/src/app/(login)/otp/[method]/set/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
getBrandingSettings,
getSession,
registerTOTP,
server,
} from "@/lib/zitadel";
import Alert from "@/ui/Alert";
import { Button, ButtonVariants } from "@/ui/Button";
Expand All @@ -13,9 +12,8 @@ import { Spinner } from "@/ui/Spinner";
import TOTPRegister from "@/ui/TOTPRegister";
import UserAvatar from "@/ui/UserAvatar";
import { getMostRecentCookieWithLoginname } from "@/utils/cookies";
import { RegisterTOTPResponse } from "@zitadel/server";
import Link from "next/link";
import { ClientError } from "nice-grpc";
import { RegisterTOTPResponse } from "@zitadel/proto/zitadel/user/v2beta/user_service_pb";

export default async function Page({
searchParams,
Expand All @@ -28,11 +26,11 @@ export default async function Page({
searchParams;
const { method } = params;

const branding = await getBrandingSettings(server, organization);
const branding = await getBrandingSettings(organization);
const { session, token } = await loadSession(loginName, organization);

let totpResponse: RegisterTOTPResponse | undefined,
totpError: ClientError | undefined;
totpError: Error | undefined;
if (session && session.factors?.user?.id) {
if (method === "time-based") {
await registerTOTP(session.factors.user.id)
Expand Down Expand Up @@ -63,7 +61,7 @@ export default async function Page({
organization,
);

return getSession(server, recent.id, recent.token).then((response) => {
return getSession(recent.id, recent.token).then((response) => {
return { session: response?.session, token: recent.token };
});
}
Expand Down Expand Up @@ -111,7 +109,7 @@ export default async function Page({

{totpError && (
<div className="py-4">
<Alert>{totpError?.details}</Alert>
<Alert>{totpError?.message}</Alert>
</div>
)}

Expand Down
6 changes: 3 additions & 3 deletions apps/login/src/app/(login)/passkey/add/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getBrandingSettings, getSession, server } from "@/lib/zitadel";
import { getBrandingSettings, getSession } from "@/lib/zitadel";
import Alert, { AlertType } from "@/ui/Alert";
import DynamicTheme from "@/ui/DynamicTheme";
import RegisterPasskey from "@/ui/RegisterPasskey";
Expand All @@ -20,7 +20,7 @@ export default async function Page({
loginName,
organization,
);
return getSession(server, recent.id, recent.token).then((response) => {
return getSession(recent.id, recent.token).then((response) => {
if (response?.session) {
return response.session;
}
Expand All @@ -33,7 +33,7 @@ export default async function Page({
? "When set up, you will be able to authenticate without a password."
: "Your device will ask for your fingerprint, face, or screen lock";

const branding = await getBrandingSettings(server, organization);
const branding = await getBrandingSettings(organization);

return (
<DynamicTheme branding={branding}>
Expand Down
Loading

0 comments on commit 89671e1

Please sign in to comment.