Skip to content

Commit f793fe4

Browse files
committed
refactor: clean up auth logic more
1 parent 881d4a3 commit f793fe4

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
7474
const [searchParams] = useSearchParams();
7575
const disabledParamsList = searchParams?.get("disable_params")?.split(",");
7676

77-
const { authErrors, errorCount } = getAuthErrors(externalAuth);
77+
const authErrors = getAuthErrors(externalAuth);
7878
const form: FormikContextType<TypesGen.CreateWorkspaceRequest> =
7979
useFormik<TypesGen.CreateWorkspaceRequest>({
8080
initialValues: {
@@ -91,6 +91,7 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
9191
}),
9292
enableReinitialize: true,
9393
onSubmit: (request) => {
94+
const errorCount = Object.keys(authErrors).length;
9495
if (errorCount > 0) {
9596
form.setSubmitting(false);
9697
return;
@@ -242,22 +243,19 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
242243
);
243244
};
244245

245-
type ExternalAuthErrors = Record<string, string>;
246-
246+
type VerifiableAuth = Readonly<{ authenticated: boolean; id: string }>;
247247
function getAuthErrors(
248-
externalAuth: readonly TypesGen.TemplateVersionExternalAuth[],
249-
) {
250-
const authErrors: ExternalAuthErrors = {};
251-
let errorCount = 0;
248+
authList: readonly VerifiableAuth[],
249+
): Readonly<Record<string, string>> {
250+
const authErrors: Record<string, string> = {};
252251

253-
for (const auth of externalAuth) {
252+
for (const auth of authList) {
254253
if (!auth.authenticated) {
255254
authErrors[auth.id] = "You must authenticate to create a workspace!";
256-
errorCount++;
257255
}
258256
}
259257

260-
return { authErrors, errorCount } as const;
258+
return authErrors;
261259
}
262260

263261
const useStyles = makeStyles((theme) => ({

0 commit comments

Comments
 (0)