-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #899 from ensdomains/dentity-oauth-from-unconnecte…
…d-fix Fix enter verification process from unconnected state
- Loading branch information
Showing
7 changed files
with
122 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { QueryFunctionContext, useQuery } from '@tanstack/react-query' | ||
|
||
import { VERIFICATION_OAUTH_BASE_URL } from '@app/constants/verification' | ||
import { useQueryOptions } from '@app/hooks/useQueryOptions' | ||
import { CreateQueryKey, QueryConfig } from '@app/types' | ||
import { prepareQueryOptions } from '@app/utils/prepareQueryOptions' | ||
|
||
export type DentityFederatedToken = { | ||
name: string | ||
verifiedPresentationUri: string | ||
} | ||
|
||
type UseDentityTokenParameters = { | ||
code?: string | null | ||
} | ||
|
||
export type UseDentityTokenReturnType = DentityFederatedToken | ||
|
||
type UseVerificationOAuthConfig = QueryConfig<UseDentityTokenReturnType, Error> | ||
|
||
type QueryKey<TParams extends UseDentityTokenParameters> = CreateQueryKey< | ||
TParams, | ||
'getDentityToken', | ||
'independent' | ||
> | ||
|
||
export const getDentityToken = async <TParams extends UseDentityTokenParameters>({ | ||
queryKey: [{ code }], | ||
}: QueryFunctionContext<QueryKey<TParams>>): Promise<UseDentityTokenReturnType> => { | ||
// Get federated token from oidc worker | ||
const url = `${VERIFICATION_OAUTH_BASE_URL}/dentity/token` | ||
const response = await fetch(url, { | ||
method: 'POST', | ||
body: JSON.stringify({ code }), | ||
}) | ||
const json = await response.json() | ||
|
||
return json as UseDentityTokenReturnType | ||
} | ||
|
||
export const useDentityToken = <TParams extends UseDentityTokenParameters>({ | ||
enabled = true, | ||
gcTime, | ||
scopeKey, | ||
...params | ||
}: TParams & UseVerificationOAuthConfig) => { | ||
const initialOptions = useQueryOptions({ | ||
params, | ||
scopeKey, | ||
functionName: 'getDentityToken', | ||
queryDependencyType: 'independent', | ||
queryFn: getDentityToken, | ||
}) | ||
|
||
const preparedOptions = prepareQueryOptions({ | ||
queryKey: initialOptions.queryKey, | ||
queryFn: initialOptions.queryFn, | ||
enabled: enabled && !!params.code, | ||
gcTime, | ||
staleTime: Infinity, | ||
retry: 0, | ||
}) | ||
|
||
const query = useQuery(preparedOptions) | ||
|
||
return query | ||
} |
9 changes: 0 additions & 9 deletions
9
src/hooks/verification/useVerificationOAuth/utils/getAPIEndpointForVerifier.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.