Skip to content

Commit 1b81555

Browse files
committed
convert Login.ts
1 parent 0e00e3d commit 1b81555

File tree

3 files changed

+44
-11
lines changed

3 files changed

+44
-11
lines changed

components/dashboard/src/Login.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7-
import { AuthProviderInfo } from "@gitpod/gitpod-protocol";
87
import * as GitpodCookie from "@gitpod/gitpod-protocol/lib/util/gitpod-cookie";
98
import { useContext, useEffect, useState, useMemo, useCallback, FC } from "react";
109
import { UserContext } from "./user-context";
@@ -18,9 +17,10 @@ import { getURLHash } from "./utils";
1817
import ErrorMessage from "./components/ErrorMessage";
1918
import { Heading1, Heading2, Subheading } from "./components/typography/headings";
2019
import { SSOLoginForm } from "./login/SSOLoginForm";
21-
import { useAuthProviders } from "./data/auth-providers/auth-provider-query";
20+
import { useAuthProviderDescriptions } from "./data/auth-providers/auth-provider-query";
2221
import { SetupPending } from "./login/SetupPending";
2322
import { useNeedsSetup } from "./dedicated-setup/use-needs-setup";
23+
import { AuthProviderDescription } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
2424

2525
export function markLoggedIn() {
2626
document.cookie = GitpodCookie.generateCookie(window.location.hostname);
@@ -38,7 +38,7 @@ export const Login: FC<LoginProps> = ({ onLoggedIn }) => {
3838

3939
const urlHash = useMemo(() => getURLHash(), []);
4040

41-
const authProviders = useAuthProviders();
41+
const authProviderDescriptions = useAuthProviderDescriptions();
4242
const [errorMessage, setErrorMessage] = useState<string | undefined>(undefined);
4343
const [hostFromContext, setHostFromContext] = useState<string | undefined>();
4444
const [repoPathname, setRepoPathname] = useState<string | undefined>();
@@ -58,9 +58,9 @@ export const Login: FC<LoginProps> = ({ onLoggedIn }) => {
5858
}
5959
}, [urlHash]);
6060

61-
let providerFromContext: AuthProviderInfo | undefined;
62-
if (hostFromContext && authProviders.data) {
63-
providerFromContext = authProviders.data.find((provider) => provider.host === hostFromContext);
61+
let providerFromContext: AuthProviderDescription | undefined;
62+
if (hostFromContext && authProviderDescriptions.data) {
63+
providerFromContext = authProviderDescriptions.data.find((provider) => provider.host === hostFromContext);
6464
}
6565

6666
const updateUser = useCallback(async () => {
@@ -158,19 +158,19 @@ export const Login: FC<LoginProps> = ({ onLoggedIn }) => {
158158
className="btn-login flex-none w-56 h-10 p-0 inline-flex rounded-xl"
159159
onClick={() => openLogin(providerFromContext!.host)}
160160
>
161-
{iconForAuthProvider(providerFromContext.authProviderType)}
161+
{iconForAuthProvider(providerFromContext.type)}
162162
<span className="pt-2 pb-2 mr-3 text-sm my-auto font-medium truncate overflow-ellipsis">
163163
Continue with {simplifyProviderName(providerFromContext.host)}
164164
</span>
165165
</button>
166166
) : (
167-
authProviders.data?.map((ap) => (
167+
authProviderDescriptions.data?.map((ap) => (
168168
<button
169169
key={"button" + ap.host}
170170
className="btn-login flex-none w-56 h-10 p-0 inline-flex rounded-xl"
171171
onClick={() => openLogin(ap.host)}
172172
>
173-
{iconForAuthProvider(ap.authProviderType)}
173+
{iconForAuthProvider(ap.type)}
174174
<span className="pt-2 pb-2 mr-3 text-sm my-auto font-medium truncate overflow-ellipsis">
175175
Continue with {simplifyProviderName(ap.host)}
176176
</span>
@@ -179,7 +179,10 @@ export const Login: FC<LoginProps> = ({ onLoggedIn }) => {
179179
)}
180180
<SSOLoginForm
181181
onSuccess={authorizeSuccessful}
182-
singleOrgMode={!!authProviders.data && authProviders.data.length === 0}
182+
singleOrgMode={
183+
!!authProviderDescriptions.data &&
184+
authProviderDescriptions.data.length === 0
185+
}
183186
/>
184187
</div>
185188
{errorMessage && <ErrorMessage imgSrc={exclamation} message={errorMessage} />}

components/dashboard/src/data/auth-providers/auth-provider-query.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
import { AuthProviderInfo } from "@gitpod/gitpod-protocol";
88
import { useQuery } from "@tanstack/react-query";
99
import { getGitpodService } from "../../service/service";
10+
import { authProviderClient } from "../../service/public-api";
11+
import { useCurrentUser } from "../../user-context";
12+
import {
13+
AuthProviderDescription,
14+
ListAuthProviderDescriptionsRequest,
15+
} from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
1016

1117
export const useAuthProviders = () => {
1218
return useQuery<AuthProviderInfo[]>({
@@ -16,3 +22,22 @@ export const useAuthProviders = () => {
1622
},
1723
});
1824
};
25+
26+
export const useAuthProviderDescriptions = () => {
27+
const user = useCurrentUser();
28+
const query = useQuery<AuthProviderDescription[]>({
29+
queryKey: ["auth-provider-descriptions"],
30+
queryFn: async () => {
31+
const params = new ListAuthProviderDescriptionsRequest();
32+
if (user) {
33+
params.id = {
34+
case: "userId",
35+
value: user.id,
36+
};
37+
}
38+
const response = await authProviderClient.listAuthProviderDescriptions(params);
39+
return response.descriptions;
40+
},
41+
});
42+
return query;
43+
};

components/dashboard/src/provider-utils.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,25 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7+
import { AuthProviderType } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
78
import bitbucket from "./images/bitbucket.svg";
89
import github from "./images/github.svg";
910
import gitlab from "./images/gitlab.svg";
1011
import { gitpodHostUrl } from "./service/service";
1112

12-
function iconForAuthProvider(type: string) {
13+
function iconForAuthProvider(type: string | AuthProviderType) {
1314
switch (type) {
1415
case "GitHub":
16+
case AuthProviderType.GITHUB:
1517
return <img className="fill-current dark:filter-invert w-5 h-5 ml-3 mr-3 my-auto" src={github} alt="" />;
1618
case "GitLab":
19+
case AuthProviderType.GITLAB:
1720
return <img className="fill-current filter-grayscale w-5 h-5 ml-3 mr-3 my-auto" src={gitlab} alt="" />;
1821
case "Bitbucket":
22+
case AuthProviderType.BITBUCKET:
1923
return <img className="fill-current filter-grayscale w-5 h-5 ml-3 mr-3 my-auto" src={bitbucket} alt="" />;
2024
case "BitbucketServer":
25+
case AuthProviderType.BITBUCKET_SERVER:
2126
return <img className="fill-current filter-grayscale w-5 h-5 ml-3 mr-3 my-auto" src={bitbucket} alt="" />;
2227
default:
2328
return <></>;

0 commit comments

Comments
 (0)