@@ -11,7 +11,15 @@ import { LatteAuthenticateOptions } from "./types";
1111class Latte {
1212 public authgear : WebContainer ;
1313 public customUIEndpoint : string ;
14- public tokenizeEndpoint : string ;
14+ public middlewareEndpoint : string ;
15+
16+ private get tokenizeEndpoint ( ) : string {
17+ return `${ this . middlewareEndpoint } /token` ;
18+ }
19+ private get proofOfPhoneNumberVerificationEndpoint ( ) : string {
20+ return `${ this . middlewareEndpoint } /proof_of_phone_number_verification
21+ ` ;
22+ }
1523
1624 private flows : LatteFlows ;
1725
@@ -20,11 +28,11 @@ class Latte {
2028 constructor (
2129 authgear : WebContainer ,
2230 customUIEndpoint : string ,
23- tokenizeEndpoint : string
31+ middlewareEndpoint : string
2432 ) {
2533 this . authgear = authgear ;
2634 this . customUIEndpoint = customUIEndpoint ;
27- this . tokenizeEndpoint = tokenizeEndpoint ;
35+ this . middlewareEndpoint = middlewareEndpoint ;
2836
2937 this . flows = new LatteFlows ( this ) ;
3038 }
@@ -62,6 +70,25 @@ class Latte {
6270 }
6371 return resp . text ( ) ;
6472 }
73+
74+ public async getProofOfPhoneNumberVerification ( ) : Promise < string > {
75+ await this . authgear . refreshAccessTokenIfNeeded ( ) ;
76+ const accessToken = this . authgear . accessToken ;
77+ if ( accessToken == null ) {
78+ throw new LatteError ( "getProofOfPhoneNumberVerification requires authenticated user" ) ;
79+ }
80+
81+ const resp = await this . fetch ( this . proofOfPhoneNumberVerificationEndpoint , {
82+ method : "POST" ,
83+ body : JSON . stringify ( { access_token : accessToken } ) ,
84+ credentials : "omit" ,
85+ } ) ;
86+ if ( ! resp . ok ) {
87+ throw new LatteError ( "unexpected response from proofOfPhoneNumberVerification endpoint" , resp ) ;
88+ }
89+ const json = await resp . json ( ) ;
90+ return json [ "proof_of_phone_number_verification" ] ;
91+ }
6592}
6693
6794export { Latte } ;
0 commit comments