Skip to content

Commit

Permalink
Fix bug when polling auth req after creation
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel committed Jun 28, 2024
1 parent 5361325 commit f9ef5c6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 24 deletions.
25 changes: 2 additions & 23 deletions apps/devtool/src/app/_hooks/useAuthServerApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {
} from '@narval/armory-sdk'
import { AuthorizationRequest } from '@narval/policy-engine-shared'
import { SigningAlg } from '@narval/signature'
import { useEffect, useMemo, useState } from 'react'
import useSWR from 'swr'
import { useMemo, useState } from 'react'
import { extractErrorMessage, getUrlProtocol } from '../_lib/utils'
import useAccountSignature from './useAccountSignature'
import useStore from './useStore'
Expand Down Expand Up @@ -57,26 +56,6 @@ const useAuthServerApi = () => {
})
}, [authHost, authClientId, authClientSecret, jwk, signer])

const { data: authorizationResponse } = useSWR(
'/authorization-requests',
() => {
if (!authClient || !processingRequest) {
return null
}

return authClient.getAuthorizationById(processingRequest.id)
},
{ refreshInterval: 1000 }
)

useEffect(() => {
if (!authorizationResponse) return

if (COMPLETED_STATUS.includes(authorizationResponse.status)) {
setProcessingRequest(undefined)
}
}, [authorizationResponse])

const ping = () => {
if (!authClient) return

Expand Down Expand Up @@ -187,7 +166,7 @@ const useAuthServerApi = () => {
}
}

return { errors, isProcessing, isSynced, authorizationResponse, ping, createClient, sync, evaluate }
return { errors, isProcessing, isSynced, ping, createClient, sync, evaluate }
}

export default useAuthServerApi
2 changes: 1 addition & 1 deletion packages/armory-sdk/src/lib/auth/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class AuthClient {
* @returns A Promise that resolves to the retrieved AuthorizationResponseDto.
*/
async getAuthorizationById(id: string): Promise<AuthorizationResponseDto> {
const { data } = await this.authorizationHttp.getById(this.config.clientId, id)
const { data } = await this.authorizationHttp.getById(id, this.config.clientId)

return data
}
Expand Down

0 comments on commit f9ef5c6

Please sign in to comment.