From 07901d62e1b68c5e06a6d55a3c5e9d8cdb8ad010 Mon Sep 17 00:00:00 2001 From: "tomosa.sarkar" Date: Fri, 17 Oct 2025 15:58:49 +0530 Subject: [PATCH] feat : otp api changed --- src/app/_util/otp.ts | 42 ++++++++++++++++++++++++------------------ src/app/login/page.tsx | 2 +- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/app/_util/otp.ts b/src/app/_util/otp.ts index da02eca..e7f775b 100644 --- a/src/app/_util/otp.ts +++ b/src/app/_util/otp.ts @@ -32,13 +32,15 @@ function getStoredMobileNumber(): string | null { export async function sendOtp(payload: SendOtpPayload) { try { const mobileNumber = payload.mobileNumber || getStoredMobileNumber(); - const response = await axios.post( - 'http://localhost:8080/api/otp/send', - { ...payload, mobileNumber }, - { headers: { 'Content-Type': 'application/json' } } - ); + const response = await fetch('api/otp/send', { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ ...payload,mobileNumber}), + }) console.log('otp sended.'); - return response.data; + return await response.json(); } catch (error: any) { console.error('Error sending OTP:', error.response?.data || error.message); throw error.response?.data || error; @@ -48,13 +50,15 @@ export async function sendOtp(payload: SendOtpPayload) { export async function verifyOtp(otp: string) { try { const mobileNumber = getStoredMobileNumber(); - const response = await axios.post( - `http://localhost:8080/api/otp/verify?mobileNumber=${mobileNumber}`, - { otp }, - { headers: { 'Content-Type': 'application/json' } } - ); + const response = await fetch(`/api/otp/verify?mobileNumber=${mobileNumber}`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({otp}), + }) console.log('Otp verified'); - return response.data; + return await response.json(); } catch (error: any) { console.error('Error verifying OTP:', error.response?.data || error.message); throw error.response?.data || error; @@ -64,13 +68,15 @@ export async function verifyOtp(otp: string) { export async function verifyLoginOtp(otp: string, mobileNumber: string) { try { // const mobileNumber = getStoredMobileNumber(); - const response = await axios.post( - `http://localhost:8080/api/otp/verify?mobileNumber=${mobileNumber}`, - { otp }, - { headers: { 'Content-Type': 'application/json' } } - ); + const response = await fetch(`/api/otp/verify?mobileNumber=${mobileNumber}`, { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({otp}), + }) console.log('Otp verified.'); - return response.data; + return await response.json(); } catch (error: any) { console.error('Error verifying OTP:', error.response?.data || error.message); throw error.response?.data || error; diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index cf4f7bf..91a3a0e 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -193,7 +193,7 @@ export default function Login() { setMobile(data.mobile); setOtpRequired(true); setButtonLabel("Verify OTP"); - + const otpSent = await handleSendOtp(data.mobile); // if (otpSent) { // notifications.show({