Skip to content

Commit

Permalink
feat: migrate loginname page to buf
Browse files Browse the repository at this point in the history
  • Loading branch information
yordis committed May 29, 2024
1 parent 61f890f commit 1946305
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 193 deletions.
37 changes: 24 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# ZITADEL TypeScript with Turborepo and Changesets

This repository contains all TypeScript and JavaScript packages and applications you need to create your own ZITADEL Login UI.
The repo makes use of the [build system Turbo](https://turbo.build/repo) and the [Changesets CLI for versioning the packages](https://github.com/changesets/changesets).
This repository contains all TypeScript and JavaScript packages and applications you need to create your own ZITADEL
Login UI.
The repo makes use of the [build system Turbo](https://turbo.build/repo) and
the [Changesets CLI for versioning the packages](https://github.com/changesets/changesets).

**⚠️ This repo and packages are in alpha state and subject to change ⚠️**

The scope of functionality of this repo and packages is limited and under active development.
Once the package structure is set and all APIs are fully implemented we'll move this repo to beta state.
You can read the [contribution guide](/CONTRIBUTING.md) on how to contribute.
Questions can be raised in our [Discord channel](https://discord.gg/erh5Brh7jE) or as a [GitHub issue](https://github.com/zitadel/typescript/issues).
Questions can be raised in our [Discord channel](https://discord.gg/erh5Brh7jE) or as
a [GitHub issue](https://github.com/zitadel/typescript/issues).

## Developing Your Own ZITADEL Login UI

Expand All @@ -25,8 +28,8 @@ We think the easiest path of getting up and running, is the following:
## Included Apps And Packages

- `login`: The login UI used by ZITADEL Cloud, powered by Next.js
- `@zitadel/server`: core components for establishing node client connection, grpc stub
- `@zitadel/client`: core components for establishing web client connection, grpc stub
- `@zitadel/node`: core components for establishing node client connection, grpc stub
- `@zitadel/client`: shared client utilities
- `@zitadel/proto`: shared protobuf types
- `@zitadel/react`: shared React utilities and components built with tailwindcss
- `@zitadel/next`: shared Next.js utilities
Expand All @@ -38,9 +41,11 @@ Each package and app is 100% [TypeScript](https://www.typescriptlang.org/).
### Login

The login is currently in a work in progress state.
The goal is to implement a login UI, using the session API of ZITADEL, which also implements the OIDC Standard and is ready to use for everyone.
The goal is to implement a login UI, using the session API of ZITADEL, which also implements the OIDC Standard and is
ready to use for everyone.

In the first phase we want to have a MVP login ready with the OIDC Standard and a basic feature set. In a second step the features will be extended.
In the first phase we want to have a MVP login ready with the OIDC Standard and a basic feature set. In a second step
the features will be extended.

This list should show the current implementation state, and also what is missing.
You can already use the current state, and extend it with your needs.
Expand Down Expand Up @@ -105,11 +110,14 @@ You can already use the current state, and extend it with your needs.
## Versioning And Publishing Packages

Package publishing has been configured using [Changesets](https://github.com/changesets/changesets).
Here is their [documentation](https://github.com/changesets/changesets#documentation) for more information about the workflow.
Here is their [documentation](https://github.com/changesets/changesets#documentation) for more information about the
workflow.

The [GitHub Action](https://github.com/changesets/action) needs an `NPM_TOKEN` and `GITHUB_TOKEN` in the repository settings. The [Changesets bot](https://github.com/apps/changeset-bot) should also be installed on the GitHub repository.
The [GitHub Action](https://github.com/changesets/action) needs an `NPM_TOKEN` and `GITHUB_TOKEN` in the repository
settings. The [Changesets bot](https://github.com/apps/changeset-bot) should also be installed on the GitHub repository.

Read the [changesets documentation](https://github.com/changesets/changesets/blob/main/docs/automating-changesets.md) for more information about this automation
Read the [changesets documentation](https://github.com/changesets/changesets/blob/main/docs/automating-changesets.md)
for more information about this automation

### NPM

Expand All @@ -136,8 +144,10 @@ pnpm install
```

then setup the environment for the login application which needs a `.env.local` in `/apps/login`.
Go to your instance and create a service user for the application having the IAM_OWNER manager role.
This user is required to have access to create users on your primary organization and reading policy data so it can be restricted to your personal use case but we'll stick with IAM_OWNER for convenience. Create a PAT and copy the value to paste it under the `ZITADEL_SERVICE_USER_TOKEN` key.
Go to your instance and create a service user for the application having the `IAM_OWNER` manager role.
This user is required to have access to create users on your primary organization and reading policy data so it can be
restricted to your personal use case but we'll stick with `IAM_OWNER` for convenience. Create a PAT and copy the value to
paste it under the `ZITADEL_SERVICE_USER_TOKEN` key.
The file should look as follows:

```
Expand All @@ -164,7 +174,8 @@ Open the login application with your favorite browser at `localhost:3000`.

To deploy your own version on Vercel, navigate to your instance and create a service user.
Copy its id from the overview and set it as ZITADEL_SERVICE_USER_ID.
Then create a personal access token (PAT), copy and set it as ZITADEL_SERVICE_USER_TOKEN, then navigate to your instance settings and make sure it gets IAM_OWNER permissions.
Then create a personal access token (PAT), copy and set it as ZITADEL_SERVICE_USER_TOKEN, then navigate to your instance
settings and make sure it gets IAM_OWNER permissions.
Finally set your instance url as ZITADEL_API_URL. Make sure to set it without trailing slash.

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fzitadel%2Ftypescript&env=ZITADEL_API_URL,ZITADEL_SERVICE_USER_ID,ZITADEL_SERVICE_USER_TOKEN&root-directory=apps/login&envDescription=Setup%20a%20service%20account%20with%20IAM_OWNER%20membership%20on%20your%20instance%20and%20provide%20its%20id%20and%20personal%20access%20token.&project-name=zitadel-login&repository-name=zitadel-login)
3 changes: 3 additions & 0 deletions apps/login/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
"@heroicons/react": "2.0.13",
"@tailwindcss/forms": "0.5.3",
"@vercel/analytics": "^1.0.0",
"@zitadel/proto": "workspace:*",
"@zitadel/client": "workspace:*",
"@zitadel/client2": "workspace:*",
"@zitadel/react": "workspace:*",
"@zitadel/node": "workspace:*",
"@zitadel/server": "workspace:*",
"clsx": "1.2.1",
"copy-to-clipboard": "^3.3.3",
Expand Down
69 changes: 24 additions & 45 deletions apps/login/src/app/(login)/loginname/page.tsx
Original file line number Diff line number Diff line change
@@ -1,73 +1,52 @@
import {
getBrandingSettings,
getLegalAndSupportSettings,
getLoginSettings,
server,
} from "@/lib/zitadel";
import DynamicTheme from "@/ui/DynamicTheme";
import { SignInWithIDP } from "@/ui/SignInWithIDP";
import {SignInWithIDP} from "@/ui/SignInWithIDP";
import UsernameForm from "@/ui/UsernameForm";
import {
GetActiveIdentityProvidersResponse,
IdentityProvider,
ZitadelServer,
settings,
} from "@zitadel/server";
import {settingsService} from "@/lib/zitadel2";
import {makeReqCtx} from "@zitadel/client2/v2beta";
import {toPlainMessage} from "@zitadel/client2";

function getIdentityProviders(
server: ZitadelServer,
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;
});
}

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

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

const identityProviders = await getIdentityProviders(server, organization);
const loginName = props.searchParams?.loginName;
const authRequestId = props.searchParams?.authRequestId;
const organization = props.searchParams?.organization;
const submit: boolean = props.searchParams?.submit === "true";

const loginSettings = await settingsService
.getLoginSettings({ctx: makeReqCtx(organization)});
const legalAndSupportSettings = await settingsService
.getLegalAndSupportSettings({ctx: makeReqCtx(organization)});
const activeIdentityProviders = await settingsService
.getActiveIdentityProviders({ctx: makeReqCtx(organization)});

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

const branding = await getBrandingSettings(server, organization);
const brandingSettings = toPlainMessage(
await settingsService
.getBrandingSettings({ctx: makeReqCtx(organization)})
);

return (
<DynamicTheme branding={branding}>
<DynamicTheme branding={brandingSettings.settings}>
<div className="flex flex-col items-center space-y-4">
<h1>Welcome back!</h1>
<p className="ztdl-p">Enter your login data.</p>

<UsernameForm
loginSettings={loginSettings}
loginSettings={loginSettings.settings}
loginName={loginName}
authRequestId={authRequestId}
organization={organization}
submit={submit}
/>

{legal && identityProviders && process.env.ZITADEL_API_URL && (
{legalAndSupportSettings.settings && activeIdentityProviders.identityProviders && process.env.ZITADEL_API_URL && (
<SignInWithIDP
host={host}
identityProviders={identityProviders}
identityProviders={activeIdentityProviders.identityProviders}
authRequestId={authRequestId}
organization={organization}
></SignInWithIDP>
Expand Down
12 changes: 12 additions & 0 deletions apps/login/src/lib/zitadel2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {createServerTransport} from "@zitadel/node";
import { createSettingsServiceClient } from "@zitadel/client2/v2beta";

const transport = createServerTransport(
process.env.ZITADEL_SERVICE_USER_TOKEN!,
{
baseUrl: process.env.ZITADEL_API_URL!,
httpVersion: "2",
},
);

export const settingsService = createSettingsServiceClient(transport);
1 change: 0 additions & 1 deletion apps/login/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "@zitadel/tsconfig/nextjs.json",
"compilerOptions": {
"jsx": "preserve",
"rootDir": ".",
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
Expand Down
8 changes: 4 additions & 4 deletions apps/login/turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
"dependsOn": ["^build"]
},
"test": {
"dependsOn": ["@zitadel/server#build", "@zitadel/react#build"]
"dependsOn": ["@zitadel/client2#build", "@zitadel/node#build", "@zitadel/server#build", "@zitadel/react#build"]
},
"test:integration": {
"dependsOn": ["@zitadel/server#build", "@zitadel/react#build"]
"dependsOn": ["@zitadel/client2#build", "@zitadel/node#build", "@zitadel/server#build", "@zitadel/react#build"]
},
"test:unit": {
"dependsOn": ["@zitadel/server#build"]
"dependsOn": ["@zitadel/client2#build", "@zitadel/node#build", "@zitadel/server#build"]
},
"test:watch": {
"dependsOn": ["@zitadel/server#build", "@zitadel/react#build"]
"dependsOn": ["@zitadel/client2#build", "@zitadel/node#build", "@zitadel/server#build", "@zitadel/react#build"]
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"pnpm": {
"overrides": {
"@typescript-eslint/parser": "^7.9.0"
"@typescript-eslint/parser": "^7.11.0"
}
},
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions packages/eslint-config-zitadel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"version": "0.0.0",
"main": "index.js",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"dependencies": {
"eslint-config-next": "^14.2.3",
"@typescript-eslint/parser": "^7.9.0",
"@typescript-eslint/parser": "^7.11.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react": "^7.34.2",
"eslint-config-turbo": "^1.13.3"
},
"publishConfig": {
"access": "public"
}
}
1 change: 1 addition & 0 deletions packages/zitadel-client2/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { NewAuthorizationBearerInterceptor } from "./interceptors";
export type { PartialMessage, PlainMessage } from "@bufbuild/protobuf";
export { toPlainMessage } from "@bufbuild/protobuf";
5 changes: 4 additions & 1 deletion packages/zitadel-react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extends": "@zitadel/tsconfig/react-library.json",
"include": ["."],
"exclude": ["dist", "build", "node_modules"]
"exclude": ["dist", "build", "node_modules"],
"compilerOptions": {
"types": ["@testing-library/jest-dom"]
}
}
Loading

0 comments on commit 1946305

Please sign in to comment.