Skip to content

Commit

Permalink
chore: move app code into src dir
Browse files Browse the repository at this point in the history
  • Loading branch information
yordis committed May 13, 2024
1 parent cd1cbe4 commit 2e3c1a8
Show file tree
Hide file tree
Showing 104 changed files with 518 additions and 480 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ jobs:
with:
version: 8

- name: Setup Node.js 18.x
- name: Setup Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 18.x
node-version: 20.x

- uses: pnpm/action-setup@v2
name: Install pnpm
Expand Down
10 changes: 5 additions & 5 deletions apps/login/__test__/PasswordComplexity.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { render, screen, waitFor, within } from "@testing-library/react";
import PasswordComplexity from "../ui/PasswordComplexity";
import PasswordComplexity from "@/ui/PasswordComplexity";
// TODO: Why does this not compile?
// import { ResourceOwnerType } from '@zitadel/server';

Expand Down Expand Up @@ -30,14 +30,14 @@ describe("<PasswordComplexity/>", () => {
requiresSymbol: false,
resourceOwnerType: 0, // ResourceOwnerType.RESOURCE_OWNER_TYPE_UNSPECIFIED,
}}
/>
/>,
);
});
if (expectSVGTitle === false) {
it(`should not render the feedback element`, async () => {
await waitFor(() => {
expect(
screen.queryByText(feedbackElementLabel)
screen.queryByText(feedbackElementLabel),
).not.toBeInTheDocument();
});
});
Expand All @@ -46,12 +46,12 @@ describe("<PasswordComplexity/>", () => {
await waitFor(async () => {
const svg = within(
screen.getByText(feedbackElementLabel)
.parentElement as HTMLElement
.parentElement as HTMLElement,
).findByRole("img");
expect(await svg).toHaveTextContent(expectSVGTitle);
});
});
}
}
},
);
});
4 changes: 2 additions & 2 deletions apps/login/cypress/integration/login.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe("login", () => {
cy.get('button[type="submit"]').click();
cy.location("pathname", { timeout: 10_000 }).should(
"eq",
"/passkey/add"
"/passkey/add",
);
});
});
Expand Down Expand Up @@ -160,7 +160,7 @@ describe("login", () => {
cy.visit("/loginname?loginName=john%40zitadel.com&submit=true");
cy.location("pathname", { timeout: 10_000 }).should(
"eq",
"/passkey/login"
"/passkey/login",
);
});
});
Expand Down
1 change: 1 addition & 0 deletions apps/login/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"tinycolor2": "1.4.2"
},
"devDependencies": {
"@zitadel/prettier-config": "workspace:*",
"@bufbuild/buf": "^1.14.0",
"@jest/types": "^29.5.0",
"@testing-library/jest-dom": "^5.16.5",
Expand Down
1 change: 1 addition & 0 deletions apps/login/prettier.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "@zitadel/prettier-config";
6 changes: 3 additions & 3 deletions apps/login/readme.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# ZITADEL Login UI

This is going to be our next UI for the hosted login. It's based on Next.js 13 and its introduced `app/` directory.
This is going to be our next UI for the hosted login. It's based on Next.js 13 and its introduced `app/` directory.

The Login UI should provide the following functionality:

- **Login API:** Uses the new ZITADEL Login API
- **Server Components:** Making server-first components
- **Login API:** Uses the new ZITADEL Login API
- **Server Components:** Making server-first components

## Running Locally

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Session } from "@zitadel/server";
import { getBrandingSettings, listSessions, server } from "#/lib/zitadel";
import { getAllSessionCookieIds } from "#/utils/cookies";
import { getBrandingSettings, listSessions, server } 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";
import SessionsList from "@/ui/SessionsList";
import DynamicTheme from "@/ui/DynamicTheme";

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

if (ids && ids.length) {
const response = await listSessions(
server,
ids.filter((id: string | undefined) => !!id)
ids.filter((id: string | undefined) => !!id),
);
return response?.sessions ?? [];
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

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

export default function Error({ error, reset }: any) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ProviderSlug } from "#/lib/demos";
import { getBrandingSettings, server } from "#/lib/zitadel";
import Alert, { AlertType } from "#/ui/Alert";
import DynamicTheme from "#/ui/DynamicTheme";
import IdpSignin from "#/ui/IdpSignin";
import { ProviderSlug } from "@/lib/demos";
import { getBrandingSettings, server } from "@/lib/zitadel";
import Alert, { AlertType } from "@/ui/Alert";
import DynamicTheme from "@/ui/DynamicTheme";
import IdpSignin from "@/ui/IdpSignin";
import {
AddHumanUserRequest,
IDPInformation,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ProviderSlug } from "#/lib/demos";
import { getBrandingSettings, server } from "#/lib/zitadel";
import Alert, { AlertType } from "#/ui/Alert";
import DynamicTheme from "#/ui/DynamicTheme";
import IdpSignin from "#/ui/IdpSignin";
import { ProviderSlug } from "@/lib/demos";
import { getBrandingSettings, server } from "@/lib/zitadel";
import Alert, { AlertType } from "@/ui/Alert";
import DynamicTheme from "@/ui/DynamicTheme";
import IdpSignin from "@/ui/IdpSignin";
import {
AddHumanUserRequest,
IDPInformation,
Expand Down Expand Up @@ -63,18 +63,18 @@ const PROVIDER_MAPPING: {

function retrieveIDPIntent(
id: string,
token: string
token: string,
): Promise<RetrieveIdentityProviderIntentResponse> {
const userService = user.getUser(server);
return userService.retrieveIdentityProviderIntent(
{ idpIntentId: id, idpIntentToken: token },
{}
{},
);
}

function createUser(
provider: ProviderSlug,
info: IDPInformation
info: IDPInformation,
): Promise<string> {
const userData = PROVIDER_MAPPING[provider](info);
const userService = user.getUser(server);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {
getBrandingSettings,
getLegalAndSupportSettings,
server,
} from "#/lib/zitadel";
import DynamicTheme from "#/ui/DynamicTheme";
import { SignInWithIDP } from "#/ui/SignInWithIDP";
} from "@/lib/zitadel";
import DynamicTheme from "@/ui/DynamicTheme";
import { SignInWithIDP } from "@/ui/SignInWithIDP";
import {
GetActiveIdentityProvidersResponse,
IdentityProvider,
Expand All @@ -14,13 +14,13 @@ import {

function getIdentityProviders(
server: ZitadelServer,
orgId?: string
orgId?: string,
): Promise<IdentityProvider[] | undefined> {
const settingsService = settings.getSettings(server);
return settingsService
.getActiveIdentityProviders(
orgId ? { ctx: { orgId } } : { ctx: { instance: true } },
{}
{},
)
.then((resp: GetActiveIdentityProvidersResponse) => {
return resp.identityProviders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {
getLegalAndSupportSettings,
getLoginSettings,
server,
} from "#/lib/zitadel";
import DynamicTheme from "#/ui/DynamicTheme";
import { SignInWithIDP } from "#/ui/SignInWithIDP";
import UsernameForm from "#/ui/UsernameForm";
} from "@/lib/zitadel";
import DynamicTheme from "@/ui/DynamicTheme";
import { SignInWithIDP } from "@/ui/SignInWithIDP";
import UsernameForm from "@/ui/UsernameForm";
import {
GetActiveIdentityProvidersResponse,
IdentityProvider,
Expand All @@ -16,13 +16,13 @@ import {

function getIdentityProviders(
server: ZitadelServer,
orgId?: string
orgId?: string,
): Promise<IdentityProvider[] | undefined> {
const settingsService = settings.getSettings(server);
return settingsService
.getActiveIdentityProviders(
orgId ? { ctx: { orgId } } : { ctx: { instance: true } },
{}
{},
)
.then((resp: GetActiveIdentityProvidersResponse) => {
return resp.identityProviders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import {
getSession,
listAuthenticationMethodTypes,
server,
} from "#/lib/zitadel";
import Alert from "#/ui/Alert";
import ChooseSecondFactor from "#/ui/ChooseSecondFactor";
import DynamicTheme from "#/ui/DynamicTheme";
import UserAvatar from "#/ui/UserAvatar";
} 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";
} from "@/utils/cookies";

export default async function Page({
searchParams,
Expand All @@ -27,16 +27,16 @@ export default async function Page({

async function loadSessionByLoginname(
loginName?: string,
organization?: string
organization?: string,
) {
const recent = await getMostRecentCookieWithLoginname(
loginName,
organization
organization,
);
return getSession(server, recent.id, recent.token).then((response) => {
if (response?.session && response.session.factors?.user?.id) {
return listAuthenticationMethodTypes(
response.session.factors.user.id
response.session.factors.user.id,
).then((methods) => {
return {
factors: response.session?.factors,
Expand All @@ -52,7 +52,7 @@ export default async function Page({
return getSession(server, recent.id, recent.token).then((response) => {
if (response?.session && response.session.factors?.user?.id) {
return listAuthenticationMethodTypes(
response.session.factors.user.id
response.session.factors.user.id,
).then((methods) => {
return {
factors: response.session?.factors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import {
getUserByID,
listAuthenticationMethodTypes,
server,
} from "#/lib/zitadel";
import Alert from "#/ui/Alert";
import ChooseSecondFactorToSetup from "#/ui/ChooseSecondFactorToSetup";
import DynamicTheme from "#/ui/DynamicTheme";
import UserAvatar from "#/ui/UserAvatar";
} from "@/lib/zitadel";
import Alert from "@/ui/Alert";
import ChooseSecondFactorToSetup from "@/ui/ChooseSecondFactorToSetup";
import DynamicTheme from "@/ui/DynamicTheme";
import UserAvatar from "@/ui/UserAvatar";
import {
getMostRecentCookieWithLoginname,
getSessionCookieById,
} from "#/utils/cookies";
} from "@/utils/cookies";
import { user } from "@zitadel/server";

export default async function Page({
Expand All @@ -30,11 +30,11 @@ export default async function Page({

async function loadSessionByLoginname(
loginName?: string,
organization?: string
organization?: string,
) {
const recent = await getMostRecentCookieWithLoginname(
loginName,
organization
organization,
);
return getSession(server, recent.id, recent.token).then((response) => {
if (response?.session && response.session.factors?.user?.id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {
getLoginSettings,
getSession,
server,
} from "#/lib/zitadel";
import Alert from "#/ui/Alert";
import DynamicTheme from "#/ui/DynamicTheme";
import LoginOTP from "#/ui/LoginOTP";
import UserAvatar from "#/ui/UserAvatar";
import { getMostRecentCookieWithLoginname } from "#/utils/cookies";
} from "@/lib/zitadel";
import Alert from "@/ui/Alert";
import DynamicTheme from "@/ui/DynamicTheme";
import LoginOTP from "@/ui/LoginOTP";
import UserAvatar from "@/ui/UserAvatar";
import { getMostRecentCookieWithLoginname } from "@/utils/cookies";

export default async function Page({
searchParams,
Expand All @@ -29,7 +29,7 @@ export default async function Page({
async function loadSession(loginName?: string, organization?: string) {
const recent = await getMostRecentCookieWithLoginname(
loginName,
organization
organization,
);

return getSession(server, recent.id, recent.token).then((response) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import {
getSession,
registerTOTP,
server,
} from "#/lib/zitadel";
import Alert from "#/ui/Alert";
import { Button, ButtonVariants } from "#/ui/Button";
import DynamicTheme from "#/ui/DynamicTheme";
import { Spinner } from "#/ui/Spinner";
import TOTPRegister from "#/ui/TOTPRegister";
import UserAvatar from "#/ui/UserAvatar";
import { getMostRecentCookieWithLoginname } from "#/utils/cookies";
} from "@/lib/zitadel";
import Alert from "@/ui/Alert";
import { Button, ButtonVariants } from "@/ui/Button";
import DynamicTheme from "@/ui/DynamicTheme";
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";
Expand Down Expand Up @@ -60,7 +60,7 @@ export default async function Page({
async function loadSession(loginName?: string, organization?: string) {
const recent = await getMostRecentCookieWithLoginname(
loginName,
organization
organization,
);

return getSession(server, recent.id, recent.token).then((response) => {
Expand Down Expand Up @@ -149,8 +149,8 @@ export default async function Page({
{method === "email"
? "Code via email was successfully added."
: method === "sms"
? "Code via SMS was successfully added."
: ""}
? "Code via SMS was successfully added."
: ""}
</p>

<div className="mt-8 flex w-full flex-row items-center">
Expand Down
Loading

0 comments on commit 2e3c1a8

Please sign in to comment.