Skip to content

Commit eb47000

Browse files
committed
wip useAuthenticatedUser
1 parent 6b86e9c commit eb47000

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License.AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { useQuery } from "@tanstack/react-query";
8+
import { userClient } from "../../service/public-api";
9+
import { GetAuthenticatedUserRequest, User } from "@gitpod/public-api/lib/gitpod/v1/user_pb";
10+
11+
export const useAuthenticatedUser = () => {
12+
const query = useQuery<User>({
13+
queryKey: getAuthenticatedUserQueryKey(),
14+
queryFn: async () => {
15+
const params = new GetAuthenticatedUserRequest();
16+
const response = await userClient.getAuthenticatedUser(params);
17+
return response.user!;
18+
},
19+
});
20+
return query;
21+
};
22+
23+
export const getAuthenticatedUserQueryKey = () => ["authenticated-user", {}];

components/dashboard/src/data/setup.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ import * as EnvVarClasses from "@gitpod/public-api/lib/gitpod/v1/envvar_pb";
2626
import * as PrebuildClasses from "@gitpod/public-api/lib/gitpod/v1/prebuild_pb";
2727
import * as SCMClasses from "@gitpod/public-api/lib/gitpod/v1/scm_pb";
2828
import * as SSHClasses from "@gitpod/public-api/lib/gitpod/v1/ssh_pb";
29+
import * as UserClasses from "@gitpod/public-api/lib/gitpod/v1/user_pb";
2930

3031
// This is used to version the cache
3132
// If data we cache changes in a non-backwards compatible way, increment this version
3233
// That will bust any previous cache versions a client may have stored
33-
const CACHE_VERSION = "8";
34+
const CACHE_VERSION = "9";
3435

3536
export function noPersistence(queryKey: QueryKey): QueryKey {
3637
return [...queryKey, "no-persistence"];
@@ -154,6 +155,7 @@ function initializeMessages() {
154155
...Object.values(PrebuildClasses),
155156
...Object.values(SCMClasses),
156157
...Object.values(SSHClasses),
158+
...Object.values(UserClasses),
157159
];
158160
for (const c of constr) {
159161
if ((c as any).prototype instanceof Message) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License.AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { UserService } from "@gitpod/public-api/lib/gitpod/v1/user_connect";
8+
9+
import { Code, ConnectError, PromiseClient } from "@connectrpc/connect";
10+
import { PartialMessage } from "@bufbuild/protobuf";
11+
import { GetAuthenticatedUserRequest, GetAuthenticatedUserResponse } from "@gitpod/public-api/lib/gitpod/v1/user_pb";
12+
13+
export class JsonRpcUserClient implements PromiseClient<typeof UserService> {
14+
async getAuthenticatedUser(
15+
request: PartialMessage<GetAuthenticatedUserRequest>,
16+
): Promise<GetAuthenticatedUserResponse> {
17+
throw new ConnectError("unimplemented", Code.Unimplemented);
18+
}
19+
}

components/dashboard/src/service/public-api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messag
3535
import { JsonRpcScmClient } from "./json-rpc-scm-client";
3636
import { SCMService } from "@gitpod/public-api/lib/gitpod/v1/scm_connect";
3737
import { SSHService } from "@gitpod/public-api/lib/gitpod/v1/ssh_connect";
38+
import { UserService } from "@gitpod/public-api/lib/gitpod/v1/user_connect";
3839
import { JsonRpcSSHClient } from "./json-rpc-ssh-client";
40+
import { JsonRpcUserClient } from "./json-rpc-user-client";
3941

4042
const transport = createConnectTransport({
4143
baseUrl: `${window.location.protocol}//${window.location.host}/public-api`,
@@ -67,6 +69,8 @@ export const authProviderClient = createServiceClient(AuthProviderService, new J
6769

6870
export const scmClient = createServiceClient(SCMService, new JsonRpcScmClient());
6971

72+
export const userClient = createServiceClient(UserService, new JsonRpcUserClient());
73+
7074
export const envVarClient = createServiceClient(EnvironmentVariableService, new JsonRpcEnvvarClient());
7175

7276
export const sshClient = createServiceClient(SSHService, new JsonRpcSSHClient());

0 commit comments

Comments
 (0)