Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions packages/authgear-web/src/latte/latte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ import { LatteAuthenticateOptions } from "./types";
class Latte {
public authgear: WebContainer;
public customUIEndpoint: string;
public tokenizeEndpoint: string;
public middlewareEndpoint: string;

private get tokenizeEndpoint(): string {
return `${this.middlewareEndpoint}/token`;
}
private get proofOfPhoneNumberVerificationEndpoint(): string {
return `${this.middlewareEndpoint}/proof_of_phone_number_verification
`;
}

private flows: LatteFlows;

Expand All @@ -20,11 +28,11 @@ class Latte {
constructor(
authgear: WebContainer,
customUIEndpoint: string,
tokenizeEndpoint: string
middlewareEndpoint: string
) {
this.authgear = authgear;
this.customUIEndpoint = customUIEndpoint;
this.tokenizeEndpoint = tokenizeEndpoint;
this.middlewareEndpoint = middlewareEndpoint;

this.flows = new LatteFlows(this);
}
Expand Down Expand Up @@ -62,6 +70,25 @@ class Latte {
}
return resp.text();
}

public async getProofOfPhoneNumberVerification(): Promise<string> {
await this.authgear.refreshAccessTokenIfNeeded();
const accessToken = this.authgear.accessToken;
if (accessToken == null) {
throw new LatteError("getProofOfPhoneNumberVerification requires authenticated user");
}

const resp = await this.fetch(this.proofOfPhoneNumberVerificationEndpoint, {
method: "POST",
body: JSON.stringify({ access_token: accessToken }),
credentials: "omit",
});
if (!resp.ok) {
throw new LatteError("unexpected response from proofOfPhoneNumberVerification endpoint", resp);
}
const json = await resp.json();
return json["proof_of_phone_number_verification"];
}
}

export { Latte };