Skip to content

Commit

Permalink
fix: client public information api
Browse files Browse the repository at this point in the history
  • Loading branch information
2paperstar committed Apr 30, 2024
1 parent 2124b08 commit 3e76a19
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
16 changes: 16 additions & 0 deletions src/api/client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Scopes } from "src/utils/schema";
import useSWR from "swr";

import api from ".";
Expand All @@ -10,6 +11,21 @@ interface Client {
grantScopes: string[];
}

export const getClientPublicInformation = (clientId: string) =>
api
.get<{
id: string;
uuid: string;
name: string;
recentConsent?: string[];
}>(`/client/${clientId}/public`)
.then(({ data }) => ({
id: data.id,
uuid: data.uuid,
name: data.name,
recentConsent: data.recentConsent as Scopes,
}));

export const useClients = () =>
useSWR("clients", () =>
api.get<Client[]>("/client").then(({ data }) => data),
Expand Down
15 changes: 0 additions & 15 deletions src/api/oauth.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
import { Scopes } from "src/utils/schema";

import api from ".";

export const getClientInformation = (clientId: string) =>
api
.get<{
id: string;
name: string;
recent_consent?: string[];
}>(`/idp/clients/${clientId}`)
.then(({ data }) => ({
id: data.id,
name: data.name,
recentConsent: data.recent_consent as Scopes,
}));

export const authorize = ({
clientId,
redirectUri,
Expand Down
5 changes: 3 additions & 2 deletions src/pages/Authorize/useAuthorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { useNavigate, useSearchParams } from "react-router-dom";
import { useAuth } from "src/api/auth";
import { authorize, getClientInformation } from "src/api/oauth";
import { getClientPublicInformation } from "src/api/client";
import { authorize } from "src/api/oauth";
import {
authorizeSchema,
isConsentRequiredScope,
Expand Down Expand Up @@ -46,7 +47,7 @@ const useAuthorize = () => {

const { data: clientData } = useSWR(
paramsData ? ["client", paramsData.clientId] : undefined,
([, id]) => getClientInformation(id),
([, id]) => getClientPublicInformation(id),
);
const { user, logout } = useAuth();
const navigate = useNavigate();
Expand Down

0 comments on commit 3e76a19

Please sign in to comment.