From fb9d691f6a44fc129fea4e551d85f7e4db6833b4 Mon Sep 17 00:00:00 2001 From: Koosha Lahouti Date: Wed, 6 Aug 2025 11:16:31 -0700 Subject: [PATCH] feat: add otp api --- .../components/SubmitSection.tsx | 10 ++- .../components/UserCompletionForm.tsx | 90 ++++++++++++------- src/lib/authToken.ts | 59 ++++++++---- 3 files changed, 108 insertions(+), 51 deletions(-) diff --git a/src/features/authentication/components/SubmitSection.tsx b/src/features/authentication/components/SubmitSection.tsx index 7239e20..b6b02ac 100644 --- a/src/features/authentication/components/SubmitSection.tsx +++ b/src/features/authentication/components/SubmitSection.tsx @@ -83,7 +83,15 @@ export function SubmitSection({ onSubmit, loading, error, success }: Props) { > {t('completion.registerButton')} */} - + { + const { data } = await axios.post(SEND_EMAIL_OTP_URL, { + email, + }); + return data; +} + +export async function fetchAuthToken( + email: string, + otpCode: string, ): Promise { - const body = new URLSearchParams(); - body.set('grant_type', 'password'); - body.set('username', username); - body.set('password', password); - body.set('client_id', 'harmony_identity'); - body.set('scope', 'openid harmony_identity profile offline_access'); + await sendEmailOtp(email); - const { data } = await authClient.post( - '/connect/token', - body.toString(), - ); + const body = new URLSearchParams({ + grant_type: 'otp', + client_id: 'harmony_identity', + phonenumber: '', + email, + otp_code: otpCode, + scope: 'openid profile offline_access harmony_identity', + }).toString(); + + const { data } = await axios.post(TOKEN_URL, body, { + headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + }); localStorage.setItem('authToken', data.access_token); return data;