Skip to content

Commit

Permalink
return error if dentity fetch fails
Browse files Browse the repository at this point in the history
  • Loading branch information
storywithoutend committed Aug 6, 2024
1 parent 9ed27fa commit 14737a7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/routes/v1/dentity/fetchDentityFederatedToken.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { json } from "itty-router/json"

import type { RouteParameters } from "@/types.js"
import { error } from "itty-router"

type DentityFederatedTokenResponse = {
"access_token": string,
Expand All @@ -11,6 +12,8 @@ type DentityFederatedTokenResponse = {
"federated_token": string,
"ens_name": string,
"eth_address": string
error?: string
error_description?: string
}

export const fetchDentityFederatedToken = async (
Expand All @@ -30,16 +33,16 @@ export const fetchDentityFederatedToken = async (
const resp = await fetch(`${DENTITY_BASE_ENDPOINT}/oidc/token`, { method: 'POST', body, headers: { 'Content-Type': 'application/x-www-form-urlencoded' } })
const data = await resp.json()

const { federated_token, ens_name, eth_address} = data as DentityFederatedTokenResponse
const { federated_token, ens_name, error: errorTitle, error_description} = data as DentityFederatedTokenResponse

if (!federated_token || !ens_name) return error(400, {error : errorTitle, error_description})

const url = new URL(`${DENTITY_BASE_ENDPOINT}/oidc/vp-token`)
url.searchParams.append('federated_token', federated_token)
url.searchParams.append('ens_name', ens_name)

return json({
name: ens_name,
address: eth_address,
token: federated_token,
verifiedPresentationUri: url.toString()
})
}

0 comments on commit 14737a7

Please sign in to comment.