Skip to content

Commit 7903ca3

Browse files
committed
feat(password): WIP
1 parent d50eb1d commit 7903ca3

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

site/src/api/queries/users.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,8 @@ export const updatePassword = () => {
6666

6767
export const validatePassword = () => {
6868
return {
69-
mutationFn: ({
70-
...request
71-
}: ValidateUserPasswordRequest) =>
72-
API.validateUserPassword(request.password),
73-
};
69+
mutationFn: API.validateUserPassword,
70+
}
7471
}
7572

7673
export const createUser = (queryClient: QueryClient) => {

site/src/pages/SetupPage/SetupPage.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ import { useAuthContext } from "contexts/auth/AuthProvider";
66
import { useEmbeddedMetadata } from "hooks/useEmbeddedMetadata";
77
import { type FC, useEffect, useState } from "react";
88
import { Helmet } from "react-helmet-async";
9-
import { useMutation, useQuery } from "react-query";
9+
import { useMutation, useQuery, useQueryClient } from "react-query";
1010
import { Navigate, useNavigate } from "react-router-dom";
1111
import { pageTitle } from "utils/page";
1212
import { sendDeploymentEvent } from "utils/telemetry";
1313
import { SetupPageView } from "./SetupPageView";
1414
import { useDebouncedFunction } from "hooks/debounce";
1515

16-
1716
export const SetupPage: FC = () => {
1817
const {
1918
isLoading,
@@ -23,12 +22,16 @@ export const SetupPage: FC = () => {
2322
isSigningIn,
2423
} = useAuthContext();
2524
const createFirstUserMutation = useMutation(createFirstUser());
25+
const validatePasswordMutation = useMutation(validatePassword());
26+
2627
const setupIsComplete = !isConfiguringTheFirstUser;
2728
const { metadata } = useEmbeddedMetadata();
2829
const buildInfoQuery = useQuery(buildInfo(metadata["build-info"]));
29-
const validatePasswordQuery = useQuery({...validatePassword(), enabled: true});
30+
const queryClient = useQueryClient();
3031
const navigate = useNavigate();
3132

33+
const [passwordIsValid, setPasswordIsValid] = useState(false);
34+
3235
useEffect(() => {
3336
if (!buildInfoQuery.data) {
3437
return;
@@ -53,7 +56,11 @@ export const SetupPage: FC = () => {
5356
}
5457

5558
const validateUserPassword = async (password: string) => {
56-
const isValid = await validateUserPassword(password);
59+
const isValid = validatePasswordMutation.mutate({password}, {
60+
onSuccess: (data) => {
61+
setPasswordIsValid(data.isValid);
62+
},
63+
})
5764
};
5865

5966
const { debounced: debouncedValidateUserPassword } = useDebouncedFunction(validateUserPassword, 500);
@@ -65,6 +72,7 @@ export const SetupPage: FC = () => {
6572
</Helmet>
6673
<SetupPageView
6774
onPasswordChange={debouncedValidateUserPassword}
75+
passwordIsValid={passwordIsValid}
6876
isLoading={isSigningIn || createFirstUserMutation.isLoading}
6977
error={createFirstUserMutation.error}
7078
onSubmit={async (firstUser) => {

site/src/pages/SetupPage/SetupPageView.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,17 @@ const numberOfDevelopersOptions = [
8484
];
8585

8686
export interface SetupPageViewProps {
87-
onPasswordChange?: (password: string) => void;
8887
onSubmit: (firstUser: TypesGen.CreateFirstUserRequest) => void;
88+
onPasswordChange?: (password: string) => void;
89+
passwordIsValid?: boolean;
8990
error?: unknown;
9091
isLoading?: boolean;
9192
}
9293

9394
export const SetupPageView: FC<SetupPageViewProps> = ({
94-
onPasswordChange,
9595
onSubmit,
96+
onPasswordChange,
97+
passwordIsValid = true,
9698
error,
9799
isLoading,
98100
}) => {
@@ -183,8 +185,8 @@ export const SetupPageView: FC<SetupPageViewProps> = ({
183185
id="password"
184186
label={Language.passwordLabel}
185187
type="password"
186-
error={isPasswordValid === false} // Show error if password is invalid
187-
helperText={isPasswordValid === false ? "Password is not strong enough." : ""} // Provide feedback
188+
error={!passwordIsValid} // Show error if password is invalid
189+
helperText={!passwordIsValid ? "Password is not strong enough." : ""} // Provide feedback
188190
/>
189191
<label
190192
htmlFor="trial"

0 commit comments

Comments
 (0)