@@ -4,26 +4,38 @@ import { signPairingCode } from 'react-native-bcsc-core'
4
4
import BCSCApiClient from '../client'
5
5
import { withAccount } from './withAccountGuard'
6
6
7
- // There is no actual data response (just a 200) from the pairing code login endpoint, so we
8
- // define a minimal response for DX and and TypeScript
9
- export interface PairingCodeLoginResponseData {
10
- success : boolean
7
+ export interface PairingCodeLoginClientMetadata {
8
+ transaction_id : string
9
+ client_ref_id : string
10
+ client_name : string
11
+ client_uri : string
12
+ initiate_login_uri : string
13
+ policy_uri : string
14
+ aaplication_type : string
15
+ useage_date : string
11
16
}
12
17
13
18
const usePairingApi = ( apiClient : BCSCApiClient ) => {
19
+ /**
20
+ * Logs in a user using a pairing code and returns the client metadata.
21
+ *
22
+ * @param {string } code - The pairing code to use for login.
23
+ * @returns {* } {Promise<PairingCodeLoginClientMetadata>} A promise that resolves to the client metadata.
24
+ */
14
25
const loginByPairingCode = useCallback (
15
26
async ( code : string ) => {
16
- return withAccount < PairingCodeLoginResponseData > ( async ( account ) => {
27
+ return withAccount < PairingCodeLoginClientMetadata > ( async ( account ) => {
17
28
const { issuer, clientID } = account
18
29
const { fcmDeviceToken, apnsToken } = await getNotificationTokens ( )
19
30
const signedCode = await signPairingCode ( code , issuer , clientID , fcmDeviceToken , apnsToken )
20
- await apiClient . post < PairingCodeLoginResponseData > (
31
+ const response = await apiClient . post < PairingCodeLoginClientMetadata > (
21
32
// this endpoint is not available through the .well-known/openid-configuration so it needs to be hardcoded
22
33
`${ apiClient . baseURL } /cardtap/v3/mobile/assertion` ,
23
34
{ assertion : signedCode } ,
24
35
{ headers : { 'Content-Type' : 'application/x-www-form-urlencoded' } }
25
36
)
26
- return { success : true }
37
+
38
+ return response . data
27
39
} )
28
40
} ,
29
41
[ apiClient ]
0 commit comments