feat: create kyc page with api
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { getCsrfToken } from '@shared/api/csrf'
|
||||
import { tokenStore } from '@shared/api/tokenStore'
|
||||
import { tokenStore, refreshAccessToken } from '@shared/api/tokenStore'
|
||||
|
||||
export interface KycResponse {
|
||||
status: boolean
|
||||
@@ -12,7 +12,11 @@ export interface KycResponse {
|
||||
|
||||
const KYC_API_URL = 'https://app.kyc.elcsa.ru'
|
||||
|
||||
export async function kycCreate(): Promise<KycResponse> {
|
||||
export function kycCreate(): Promise<KycResponse> {
|
||||
return doKycRequest(true)
|
||||
}
|
||||
|
||||
async function doKycRequest(allowRetry: boolean): Promise<KycResponse> {
|
||||
const csrf = await getCsrfToken()
|
||||
const bearer = tokenStore.get()
|
||||
|
||||
@@ -27,6 +31,16 @@ export async function kycCreate(): Promise<KycResponse> {
|
||||
body: JSON.stringify({}),
|
||||
})
|
||||
|
||||
if (res.status === 401 && allowRetry) {
|
||||
try {
|
||||
await refreshAccessToken()
|
||||
return doKycRequest(false)
|
||||
} catch {
|
||||
tokenStore.clear()
|
||||
throw new Error('Unauthorized')
|
||||
}
|
||||
}
|
||||
|
||||
const data = await res.json()
|
||||
if (!res.ok) throw data
|
||||
return data as KycResponse
|
||||
|
||||
Reference in New Issue
Block a user