Skip to content

Commit b3362c3

Browse files
committed
_
1 parent 1c0e39a commit b3362c3

File tree

5 files changed

+65
-62
lines changed

5 files changed

+65
-62
lines changed

coderd/database/dbmem/dbmem.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6463,7 +6463,7 @@ func (q *FakeQuerier) UpdateUserStatus(_ context.Context, arg database.UpdateUse
64636463
return database.User{}, sql.ErrNoRows
64646464
}
64656465

6466-
func (q *FakeQuerier) UpdateUserThemePreference(ctx context.Context, arg database.UpdateUserThemePreferenceParams) (database.User, error) {
6466+
func (q *FakeQuerier) UpdateUserThemePreference(_ context.Context, arg database.UpdateUserThemePreferenceParams) (database.User, error) {
64676467
err := validateDatabaseType(arg)
64686468
if err != nil {
64696469
return database.User{}, err

site/src/components/RequireAuth/RequireAuth.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { DashboardProvider } from "../Dashboard/DashboardProvider";
99
import { FullScreenLoader } from "../Loader/FullScreenLoader";
1010

1111
export const RequireAuth: FC = () => {
12-
const { signOut, isSigningOut, isSignedOut } = useAuth();
12+
const { signOut, isSigningOut, isSignedOut, isLoading } = useAuth();
1313
const location = useLocation();
1414
const isHomePage = location.pathname === "/";
1515
const navigateTo = isHomePage
@@ -37,21 +37,23 @@ export const RequireAuth: FC = () => {
3737
};
3838
}, [signOut]);
3939

40+
if (isLoading || isSigningOut) {
41+
return <FullScreenLoader />;
42+
}
43+
4044
if (isSignedOut) {
4145
return (
4246
<Navigate to={navigateTo} state={{ isRedirect: !isHomePage }} replace />
4347
);
44-
} else if (isSigningOut) {
45-
return <FullScreenLoader />;
46-
} else {
47-
// Authenticated pages have access to some contexts for knowing enabled experiments
48-
// and where to route workspace connections.
49-
return (
50-
<DashboardProvider>
51-
<ProxyProvider>
52-
<Outlet />
53-
</ProxyProvider>
54-
</DashboardProvider>
55-
);
5648
}
49+
50+
// Authenticated pages have access to some contexts for knowing enabled experiments
51+
// and where to route workspace connections.
52+
return (
53+
<DashboardProvider>
54+
<ProxyProvider>
55+
<Outlet />
56+
</ProxyProvider>
57+
</DashboardProvider>
58+
);
5759
};

site/src/contexts/AuthProvider/AuthProvider.tsx

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
import {
2+
createContext,
3+
type FC,
4+
type PropsWithChildren,
5+
useCallback,
6+
useContext,
7+
} from "react";
8+
import { useMutation, useQuery, useQueryClient } from "react-query";
19
import { checkAuthorization } from "api/queries/authCheck";
210
import {
311
authMethods,
@@ -7,25 +15,17 @@ import {
715
me,
816
updateProfile as updateProfileOptions,
917
} from "api/queries/users";
10-
import {
18+
import { isApiError } from "api/errors";
19+
import type {
1120
AuthMethods,
1221
UpdateUserProfileRequest,
1322
User,
1423
} from "api/typesGenerated";
15-
import {
16-
createContext,
17-
FC,
18-
PropsWithChildren,
19-
useCallback,
20-
useContext,
21-
} from "react";
22-
import { useMutation, useQuery, useQueryClient } from "react-query";
23-
import { permissionsToCheck, Permissions } from "./permissions";
2424
import { displaySuccess } from "components/GlobalSnackbar/utils";
25-
import { FullScreenLoader } from "components/Loader/FullScreenLoader";
26-
import { isApiError } from "api/errors";
25+
import { permissionsToCheck, type Permissions } from "./permissions";
2726

2827
type AuthContextValue = {
28+
isLoading: boolean;
2929
isSignedOut: boolean;
3030
isSigningOut: boolean;
3131
isConfiguringTheFirstUser: boolean;
@@ -88,21 +88,24 @@ export const AuthProvider: FC<PropsWithChildren> = ({ children }) => {
8888
logoutMutation.mutate();
8989
}, [logoutMutation]);
9090

91-
const signIn = async (email: string, password: string) => {
92-
await loginMutation.mutateAsync({ email, password });
93-
};
94-
95-
const updateProfile = (req: UpdateUserProfileRequest) => {
96-
updateProfileMutation.mutate(req);
97-
};
91+
const signIn = useCallback(
92+
async (email: string, password: string) => {
93+
await loginMutation.mutateAsync({ email, password });
94+
},
95+
[loginMutation],
96+
);
9897

99-
if (isLoading) {
100-
return null;
101-
}
98+
const updateProfile = useCallback(
99+
(req: UpdateUserProfileRequest) => {
100+
updateProfileMutation.mutate(req);
101+
},
102+
[updateProfileMutation],
103+
);
102104

103105
return (
104106
<AuthContext.Provider
105107
value={{
108+
isLoading,
106109
isSignedOut,
107110
isSigningOut,
108111
isConfiguringTheFirstUser,

site/src/pages/LoginPage/LoginPage.tsx

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,41 @@ export const LoginPage: FC = () => {
3333
const redirectURL = new URL(redirectTo);
3434
if (redirectURL.host !== window.location.host) {
3535
window.location.href = redirectTo;
36-
return <></>;
36+
return null;
3737
}
3838
} catch {
3939
// Do nothing
4040
}
4141
// Path based apps.
4242
if (redirectTo.includes("/apps/")) {
4343
window.location.href = redirectTo;
44-
return <></>;
44+
return null;
4545
}
4646
}
47+
4748
return <Navigate to={redirectTo} replace />;
48-
} else if (isConfiguringTheFirstUser) {
49+
}
50+
51+
if (isConfiguringTheFirstUser) {
4952
return <Navigate to="/setup" replace />;
50-
} else {
51-
return (
52-
<>
53-
<Helmet>
54-
<title>Sign in to {applicationName}</title>
55-
</Helmet>
56-
<LoginPageView
57-
authMethods={authMethods}
58-
error={signInError}
59-
isSigningIn={isSigningIn}
60-
onSignIn={async ({ email, password }) => {
61-
await signIn(email, password);
62-
navigate("/");
63-
}}
64-
/>
65-
</>
66-
);
6753
}
54+
55+
return (
56+
<>
57+
<Helmet>
58+
<title>Sign in to {applicationName}</title>
59+
</Helmet>
60+
<LoginPageView
61+
authMethods={authMethods}
62+
error={signInError}
63+
isSigningIn={isSigningIn}
64+
onSignIn={async ({ email, password }) => {
65+
await signIn(email, password);
66+
navigate("/");
67+
}}
68+
/>
69+
</>
70+
);
6871
};
6972

7073
export default LoginPage;

site/src/pages/UserSettingsPage/AppearancePage/AppearancePage.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@ export const AppearancePage: FC = () => {
1919
isLoading={updateThemePreferenceMutation.isLoading}
2020
error={updateThemePreferenceMutation.error}
2121
initialValues={{ theme_preference: me.theme_preference }}
22-
onSubmit={async (arg: any) => {
23-
console.log("going");
24-
const x = await updateThemePreferenceMutation.mutateAsync(arg);
25-
console.log(x);
26-
return x;
27-
}}
22+
onSubmit={updateThemePreferenceMutation.mutateAsync}
2823
/>
2924
</Section>
3025
</>

0 commit comments

Comments
 (0)