feat : otp api changed
This commit is contained in:
@@ -32,13 +32,15 @@ function getStoredMobileNumber(): string | null {
|
|||||||
export async function sendOtp(payload: SendOtpPayload) {
|
export async function sendOtp(payload: SendOtpPayload) {
|
||||||
try {
|
try {
|
||||||
const mobileNumber = payload.mobileNumber || getStoredMobileNumber();
|
const mobileNumber = payload.mobileNumber || getStoredMobileNumber();
|
||||||
const response = await axios.post(
|
const response = await fetch('api/otp/send', {
|
||||||
'http://localhost:8080/api/otp/send',
|
method: "POST",
|
||||||
{ ...payload, mobileNumber },
|
headers: {
|
||||||
{ headers: { 'Content-Type': 'application/json' } }
|
"Content-Type": "application/json",
|
||||||
);
|
},
|
||||||
|
body: JSON.stringify({ ...payload,mobileNumber}),
|
||||||
|
})
|
||||||
console.log('otp sended.');
|
console.log('otp sended.');
|
||||||
return response.data;
|
return await response.json();
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('Error sending OTP:', error.response?.data || error.message);
|
console.error('Error sending OTP:', error.response?.data || error.message);
|
||||||
throw error.response?.data || error;
|
throw error.response?.data || error;
|
||||||
@@ -48,13 +50,15 @@ export async function sendOtp(payload: SendOtpPayload) {
|
|||||||
export async function verifyOtp(otp: string) {
|
export async function verifyOtp(otp: string) {
|
||||||
try {
|
try {
|
||||||
const mobileNumber = getStoredMobileNumber();
|
const mobileNumber = getStoredMobileNumber();
|
||||||
const response = await axios.post(
|
const response = await fetch(`/api/otp/verify?mobileNumber=${mobileNumber}`, {
|
||||||
`http://localhost:8080/api/otp/verify?mobileNumber=${mobileNumber}`,
|
method: "POST",
|
||||||
{ otp },
|
headers: {
|
||||||
{ headers: { 'Content-Type': 'application/json' } }
|
"Content-Type": "application/json",
|
||||||
);
|
},
|
||||||
|
body: JSON.stringify({otp}),
|
||||||
|
})
|
||||||
console.log('Otp verified');
|
console.log('Otp verified');
|
||||||
return response.data;
|
return await response.json();
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('Error verifying OTP:', error.response?.data || error.message);
|
console.error('Error verifying OTP:', error.response?.data || error.message);
|
||||||
throw error.response?.data || error;
|
throw error.response?.data || error;
|
||||||
@@ -64,13 +68,15 @@ export async function verifyOtp(otp: string) {
|
|||||||
export async function verifyLoginOtp(otp: string, mobileNumber: string) {
|
export async function verifyLoginOtp(otp: string, mobileNumber: string) {
|
||||||
try {
|
try {
|
||||||
// const mobileNumber = getStoredMobileNumber();
|
// const mobileNumber = getStoredMobileNumber();
|
||||||
const response = await axios.post(
|
const response = await fetch(`/api/otp/verify?mobileNumber=${mobileNumber}`, {
|
||||||
`http://localhost:8080/api/otp/verify?mobileNumber=${mobileNumber}`,
|
method: "POST",
|
||||||
{ otp },
|
headers: {
|
||||||
{ headers: { 'Content-Type': 'application/json' } }
|
"Content-Type": "application/json",
|
||||||
);
|
},
|
||||||
|
body: JSON.stringify({otp}),
|
||||||
|
})
|
||||||
console.log('Otp verified.');
|
console.log('Otp verified.');
|
||||||
return response.data;
|
return await response.json();
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('Error verifying OTP:', error.response?.data || error.message);
|
console.error('Error verifying OTP:', error.response?.data || error.message);
|
||||||
throw error.response?.data || error;
|
throw error.response?.data || error;
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ export default function Login() {
|
|||||||
setMobile(data.mobile);
|
setMobile(data.mobile);
|
||||||
setOtpRequired(true);
|
setOtpRequired(true);
|
||||||
setButtonLabel("Verify OTP");
|
setButtonLabel("Verify OTP");
|
||||||
|
|
||||||
const otpSent = await handleSendOtp(data.mobile);
|
const otpSent = await handleSendOtp(data.mobile);
|
||||||
// if (otpSent) {
|
// if (otpSent) {
|
||||||
// notifications.show({
|
// notifications.show({
|
||||||
|
|||||||
Reference in New Issue
Block a user