diff --git a/frontend/occupi-mobile4/screens/Login/CreatePassword.tsx b/frontend/occupi-mobile4/screens/Login/CreatePassword.tsx index 3b361809..cf30b161 100644 --- a/frontend/occupi-mobile4/screens/Login/CreatePassword.tsx +++ b/frontend/occupi-mobile4/screens/Login/CreatePassword.tsx @@ -91,7 +91,7 @@ export default function CreatePassword() { if (data.password === data.confirmpassword) { const response = await userResetPassword(data.password, data.confirmpassword); toast.show({ - placement: 'bottom right', + placement: 'top', render: ({ id }) => { return ( @@ -102,7 +102,7 @@ export default function CreatePassword() { }); } else { toast.show({ - placement: 'bottom right', + placement: 'top', render: ({ id }) => { return ( diff --git a/frontend/occupi-mobile4/screens/Login/OtpVerification.tsx b/frontend/occupi-mobile4/screens/Login/OtpVerification.tsx index 1c696210..c602981f 100644 --- a/frontend/occupi-mobile4/screens/Login/OtpVerification.tsx +++ b/frontend/occupi-mobile4/screens/Login/OtpVerification.tsx @@ -10,7 +10,7 @@ import Logo from '../../screens/Login/assets/images/Occupi/Occupi-gradient.png'; import StyledExpoRouterLink from '@/components/StyledExpoRouterLink'; import { widthPercentageToDP as wp, heightPercentageToDP as hp } from 'react-native-responsive-screen'; import { LinearGradient } from 'expo-linear-gradient'; -import { VerifyUserOtpLogin, verifyUserOtpRegister } from '@/utils/auth'; +import { verifyUserOtp, VerifyUserOtpLogin, verifyUserOtpRegister } from '@/utils/auth'; const OTPSchema = z.object({ OTP: z.string().min(6, 'OTP must be at least 6 characters in length'), @@ -80,6 +80,19 @@ const OTPVerification = () => { } }); } + else if (state === 'reset_password') { + const response = await verifyUserOtp(email, pin); + toast.show({ + placement: 'top', + render: ({ id }) => { + return ( + + {response} + + ); + } + }); + } else { const response = await VerifyUserOtpLogin(email, pin); toast.show({ diff --git a/frontend/occupi-mobile4/services/authservices.ts b/frontend/occupi-mobile4/services/authservices.ts index 021c78a6..b03246ad 100644 --- a/frontend/occupi-mobile4/services/authservices.ts +++ b/frontend/occupi-mobile4/services/authservices.ts @@ -95,6 +95,28 @@ export async function verifyOtplogin(req: VerifyOTPReq): Promise { + console.log(req); + try { + const response = await axios.post("https://dev.occupi.tech/auth/verify-otp", req, { + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + withCredentials: true + }); + // console.log(response.data); + return response.data as LoginSuccess; + } catch (error) { + if (axios.isAxiosError(error) && error.response) { + // console.log(error.response.data); + return error.response.data as Unsuccessful; + } else { + throw error; + } + } +} + export async function forgotPassword(req: any): Promise { try { const response = await axios.post("https://dev.occupi.tech/auth/forgot-password", req, { diff --git a/frontend/occupi-mobile4/utils/auth.ts b/frontend/occupi-mobile4/utils/auth.ts index 6e2447de..b418ab40 100644 --- a/frontend/occupi-mobile4/utils/auth.ts +++ b/frontend/occupi-mobile4/utils/auth.ts @@ -1,7 +1,7 @@ //this folder contains functions that will call the service functions which make api requests for authentication //the purpose of this file is to refine and process the data and return these to the View -import { forgotPassword, login, logout, register, resetPassword, verifyOtplogin, verifyOtpRegister } from "../services/authservices"; +import { forgotPassword, login, logout, register, resetPassword, verifyOtp, verifyOtplogin, verifyOtpRegister } from "../services/authservices"; import { fetchNotificationSettings, fetchSecuritySettings, fetchUserDetails } from "./user"; import { router } from 'expo-router'; import * as SecureStore from 'expo-secure-store'; @@ -26,7 +26,7 @@ export async function UserLogin(email: string, password: string) { fetchNotificationSettings(email); fetchSecuritySettings(email); router.replace('/home'); - } + } else { setState('verify_otp_login'); router.replace('/verify-otp') @@ -90,30 +90,42 @@ export async function verifyUserOtpRegister(email: string, otp: string) { } } -export async function VerifyUserOtpLogin(email : string, otp : string) { +export async function VerifyUserOtpLogin(email: string, otp: string) { try { const response = await verifyOtplogin({ email: email, otp: otp }); if (response.status === 200) { - // console.log('responseee',response); - const state = await SecureStore.getItemAsync('AppState'); - console.log('staaate',state) - if (state === 'reset_password') { - storeOtp(otp); - router.replace('/create-password'); - } - else { - setState('logged_in'); - storeToken(response.data.token); - console.log('here'); - fetchUserDetails(email, response.data.token); - fetchNotificationSettings(email); - fetchSecuritySettings(email); - router.replace('/home'); - } + // console.log('responseee',response) + setState('logged_in'); + storeToken(response.data.token); + console.log('here'); + fetchUserDetails(email, response.data.token); + fetchNotificationSettings(email); + fetchSecuritySettings(email); + router.replace('/home'); + return response.message; + } + else { + console.log('woahhh', response) + return response.message; + } + } catch (error) { + console.error('Error:', error); + } +} +export async function verifyUserOtp(email: string, otp: string) { + try { + const response = await verifyOtp({ + email: email, + otp: otp + }); + console.log(response); + if (response.status === 200) { + storeOtp(otp); + router.replace('/create-password'); return response.message; } else { @@ -123,7 +135,7 @@ export async function VerifyUserOtpLogin(email : string, otp : string) { } catch (error) { console.error('Error:', error); } -} +} export async function userForgotPassword(email: string) { storeUserEmail(email); @@ -133,7 +145,7 @@ export async function userForgotPassword(email: string) { try { const response = await forgotPassword(body); if (response.status === 200) { - console.log('responseee',response); + console.log('responseee', response); setState('reset_password'); router.replace('/verify-otp'); return response.message as string; @@ -159,7 +171,7 @@ export async function userResetPassword(newPassword: string, newPasswordConfirm: try { const response = await resetPassword(body); if (response.status === 200) { - console.log('responseee',response); + console.log('responseee', response); setState('logged_in'); storeToken(response.data.token); fetchUserDetails(email, response.data.token);