選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

use-oauth.ts 890B

1234567891011121314151617181920212223242526272829
  1. import { post } from './base'
  2. import { useMutation, useQuery } from '@tanstack/react-query'
  3. const NAME_SPACE = 'oauth-provider'
  4. export type OAuthAppInfo = {
  5. app_icon: string
  6. app_label: Record<string, string>
  7. scope: string
  8. }
  9. export type OAuthAuthorizeResponse = {
  10. code: string
  11. }
  12. export const useOAuthAppInfo = (client_id: string, redirect_uri: string) => {
  13. return useQuery<OAuthAppInfo>({
  14. queryKey: [NAME_SPACE, 'authAppInfo', client_id, redirect_uri],
  15. queryFn: () => post<OAuthAppInfo>('/oauth/provider', { body: { client_id, redirect_uri } }, { silent: true }),
  16. enabled: Boolean(client_id && redirect_uri),
  17. })
  18. }
  19. export const useAuthorizeOAuthApp = () => {
  20. return useMutation({
  21. mutationKey: [NAME_SPACE, 'authorize'],
  22. mutationFn: (payload: { client_id: string }) => post<OAuthAuthorizeResponse>('/oauth/provider/authorize', { body: payload }),
  23. })
  24. }