Skip to content

Commit

Permalink
Merge branch 'findings' into qa
Browse files Browse the repository at this point in the history
  • Loading branch information
peintnermax committed Jul 16, 2024
2 parents 81f1fa3 + 985d22b commit 1c66eb8
Show file tree
Hide file tree
Showing 175 changed files with 150 additions and 129,296 deletions.
6 changes: 6 additions & 0 deletions apps/login/src/app/(login)/mfa/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
server,
} from "@/lib/zitadel";
import Alert from "@/ui/Alert";
import BackButton from "@/ui/BackButton";
import ChooseSecondFactor from "@/ui/ChooseSecondFactor";
import DynamicTheme from "@/ui/DynamicTheme";
import UserAvatar from "@/ui/UserAvatar";
Expand Down Expand Up @@ -96,6 +97,11 @@ export default async function Page({
) : (
<Alert>No second factors available to setup.</Alert>
)}

<div className="mt-8 flex w-full flex-row items-center">
<BackButton />
<span className="flex-grow"></span>
</div>
</div>
</DynamicTheme>
);
Expand Down
6 changes: 6 additions & 0 deletions apps/login/src/app/(login)/mfa/set/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
server,
} from "@/lib/zitadel";
import Alert from "@/ui/Alert";
import BackButton from "@/ui/BackButton";
import ChooseSecondFactorToSetup from "@/ui/ChooseSecondFactorToSetup";
import DynamicTheme from "@/ui/DynamicTheme";
import UserAvatar from "@/ui/UserAvatar";
Expand Down Expand Up @@ -110,6 +111,11 @@ export default async function Page({
) : (
<Alert>No second factors available to setup.</Alert>
)}

<div className="mt-8 flex w-full flex-row items-center">
<BackButton />
<span className="flex-grow"></span>
</div>
</div>
</DynamicTheme>
);
Expand Down
2 changes: 2 additions & 0 deletions apps/login/src/app/(login)/otp/[method]/set/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
server,
} from "@/lib/zitadel";
import Alert from "@/ui/Alert";
import BackButton from "@/ui/BackButton";
import { Button, ButtonVariants } from "@/ui/Button";
import DynamicTheme from "@/ui/DynamicTheme";
import { Spinner } from "@/ui/Spinner";
Expand Down Expand Up @@ -154,6 +155,7 @@ export default async function Page({
</p>

<div className="mt-8 flex w-full flex-row items-center">
<BackButton />
<span className="flex-grow"></span>
<Link
href={
Expand Down
28 changes: 28 additions & 0 deletions apps/login/src/app/api/resetpassword/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { setEmail, server, listUsers, passwordReset } from "@/lib/zitadel";
import { NextRequest, NextResponse } from "next/server";

export async function POST(request: NextRequest) {
const body = await request.json();
if (body) {
const { loginName, organization } = body;
return listUsers(loginName, organization).then((users) => {
if (
users.details &&
users.details.totalResult == 1 &&
users.result[0].userId
) {
const userId = users.result[0].userId;

return passwordReset(server, userId)
.then((resp) => {
return NextResponse.json(resp);
})
.catch((error) => {
return NextResponse.json(error, { status: 500 });
});
} else {
return NextResponse.json({ error: "User not found" }, { status: 404 });
}
});
}
}
22 changes: 22 additions & 0 deletions apps/login/src/lib/zitadel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,28 @@ export async function setEmail(
);
}

/**
*
* @param server
* @param userId the id of the user where the email should be set
* @returns the newly set email
*/
export async function passwordReset(
server: ZitadelServer,
userId: string,
): Promise<any> {
const userservice = user.getUser(server);
return userservice.passwordReset(
{
userId,
sendLink: {
notificationType: 1, // email
},
},
{},
);
}

/**
*
* @param server
Expand Down
18 changes: 18 additions & 0 deletions apps/login/src/ui/BackButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use client";

import Link from "next/link";
import { Button, ButtonVariants } from "./Button";

type Props = { hasBack?: boolean };

export default function BackButton({ hasBack }: Props) {
return hasBack || history?.length > 1 ? (
<Button
onClick={() => history.back()}
type="button"
variant={ButtonVariants.Secondary}
>
back
</Button>
) : null;
}
2 changes: 2 additions & 0 deletions apps/login/src/ui/LoginOTP.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Checks } from "@zitadel/server";
import { useForm } from "react-hook-form";
import { TextInput } from "./Input";
import { Challenges } from "@zitadel/server";
import BackButton from "./BackButton";

// either loginName or sessionId must be provided
type Props = {
Expand Down Expand Up @@ -228,6 +229,7 @@ export default function LoginOTP({
)}

<div className="mt-8 flex w-full flex-row items-center">
<BackButton />
<span className="flex-grow"></span>
<Button
type="submit"
Expand Down
9 changes: 2 additions & 7 deletions apps/login/src/ui/LoginPasskey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Button, ButtonVariants } from "./Button";
import Alert from "./Alert";
import { Spinner } from "./Spinner";
import { Checks } from "@zitadel/server";
import BackButton from "./BackButton";

// either loginName or sessionId must be provided
type Props = {
Expand Down Expand Up @@ -250,13 +251,7 @@ export default function LoginPasskey({
use password
</Button>
) : (
<Button
type="button"
variant={ButtonVariants.Secondary}
onClick={() => router.back()}
>
back
</Button>
<BackButton />
)}

<span className="flex-grow"></span>
Expand Down
39 changes: 36 additions & 3 deletions apps/login/src/ui/PasswordForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Checks,
AuthenticationMethodType,
} from "@zitadel/server";
import BackButton from "./BackButton";

type Inputs = {
password: string;
Expand Down Expand Up @@ -75,6 +76,33 @@ export default function PasswordForm({
return response;
}

async function resetPassword() {
setError("");
setLoading(true);

const res = await fetch("/api/resetpassword", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
loginName,
organization,
authRequestId,
}),
});

const response = await res.json();

setLoading(false);
if (!res.ok) {
console.log(response.details.details);
setError(response.details?.details ?? "Could not verify password");
return Promise.reject(response.details);
}
return response;
}

function submitPasswordAndContinue(value: Inputs): Promise<boolean | void> {
return submitPassword(value).then((resp) => {
// if user has mfa -> /otp/[method] or /u2f
Expand Down Expand Up @@ -200,6 +228,13 @@ export default function PasswordForm({
label="Password"
// error={errors.username?.message as string}
/>
<button
className="transition-all text-sm hover:text-primary-light-500 dark:hover:text-primary-dark-500"
onClick={() => resetPassword()}
disabled={loading}
>
Reset Password
</button>

{loginName && (
<input type="hidden" name="loginName" value={loginName} />
Expand All @@ -213,9 +248,7 @@ export default function PasswordForm({
)}

<div className="mt-8 flex w-full flex-row items-center">
{/* <Button type="button" variant={ButtonVariants.Secondary}>
back
</Button> */}
<BackButton />
<span className="flex-grow"></span>
<Button
type="submit"
Expand Down
9 changes: 2 additions & 7 deletions apps/login/src/ui/RegisterFormWithoutPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import AuthenticationMethodRadio, {
methods,
} from "./AuthenticationMethodRadio";
import Alert from "./Alert";
import BackButton from "./BackButton";

type Inputs =
| {
Expand Down Expand Up @@ -166,13 +167,7 @@ export default function RegisterFormWithoutPassword({
)}

<div className="mt-8 flex w-full flex-row items-center justify-between">
<Button
type="button"
variant={ButtonVariants.Secondary}
onClick={() => router.back()}
>
back
</Button>
<BackButton />
<Button
type="submit"
variant={ButtonVariants.Primary}
Expand Down
9 changes: 2 additions & 7 deletions apps/login/src/ui/RegisterPasskey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Spinner } from "./Spinner";
import Alert from "./Alert";
import { AuthRequest, RegisterPasskeyResponse } from "@zitadel/server";
import { coerceToArrayBuffer, coerceToBase64Url } from "@/utils/base64";
import BackButton from "./BackButton";
type Inputs = {};

type Props = {
Expand Down Expand Up @@ -216,13 +217,7 @@ export default function RegisterPasskey({
skip
</Button>
) : (
<Button
type="button"
variant={ButtonVariants.Secondary}
onClick={() => router.back()}
>
back
</Button>
<BackButton />
)}

<span className="flex-grow"></span>
Expand Down
9 changes: 2 additions & 7 deletions apps/login/src/ui/RegisterU2F.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Spinner } from "./Spinner";
import Alert from "./Alert";
import { RegisterU2FResponse } from "@zitadel/server";
import { coerceToArrayBuffer, coerceToBase64Url } from "@/utils/base64";
import BackButton from "./BackButton";
type Inputs = {};

type Props = {
Expand Down Expand Up @@ -191,13 +192,7 @@ export default function RegisterU2F({
)}

<div className="mt-8 flex w-full flex-row items-center">
<Button
type="button"
variant={ButtonVariants.Secondary}
onClick={() => router.back()}
>
back
</Button>
<BackButton />

<span className="flex-grow"></span>
<Button
Expand Down
5 changes: 5 additions & 0 deletions apps/login/src/ui/SignInWithIDP.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { useRouter } from "next/navigation";
import { ProviderSlug } from "@/lib/demos";
import Alert from "./Alert";
import BackButton from "./BackButton";

export interface SignInWithIDPProps {
children?: ReactNode;
Expand Down Expand Up @@ -141,6 +142,10 @@ export function SignInWithIDP({
<Alert>{error}</Alert>
</div>
)}
<div className="mt-8 flex w-full flex-row items-center">
<BackButton />
<span className="flex-grow"></span>
</div>
</div>
);
}
Expand Down
1 change: 1 addition & 0 deletions packages/zitadel-proto/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zitadel
Loading

0 comments on commit 1c66eb8

Please sign in to comment.