Skip to content

Commit

Permalink
Merge pull request #847 from haseebzaki-07/new_branch_6
Browse files Browse the repository at this point in the history
Add Dynamic API calls
  • Loading branch information
manikumarreddyu authored Nov 7, 2024
2 parents 306986e + 6c418f5 commit 0be3710
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
6 changes: 5 additions & 1 deletion frontend/src/components/EmailVerification.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ const AccountVerificationPage = () => {
const [email, setEmail] = useState("");
const [otp, setOtp] = useState("");
const [isVerified, setIsVerified] = useState(false);
const ApiUrl = process.env.NODE_ENV === 'production'
? 'https://agrotech-ai-11j3.onrender.com'
: 'http://localhost:8080';


const handleVerifyAccount = async () => {
try {
await axios.post("https://agro-tech-ai-backend-teal.vercel.app/auth/verify-emailotp", { email, otp });
await axios.post(`${ApiUrl}/auth/verify-emailotp`, { email, otp });
toast.success("Account verified successfully. Redirecting to login...");
setTimeout(() => setIsVerified(true), 2000); // Redirect after a short delay
} catch (error) {
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/components/LoginPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ const LoginPage = () => {
const [showPassword, setShowPassword] = useState(false);
const [rememberMe, setRememberMe] = useState(false);
const { isLoggedIn, login } = useAuth();
const ApiUrl = process.env.NODE_ENV === 'production'
? 'https://agrotech-ai-11j3.onrender.com'
: 'http://localhost:8080';


// Handle standard email/password login
const handleSignIn = async (e) => {
e.preventDefault();
try {
const response = await axios.post(
"https://agro-tech-ai-backend-teal.vercel.app/auth/signin",
`${ApiUrl}/auth/signin`,
{
email,
password,
Expand All @@ -36,7 +40,7 @@ const LoginPage = () => {

// Google Login handler
const handleGoogleSignIn = () => {
window.location.href = "https://agro-tech-ai-backend-teal.vercel.app/auth/google";
window.location.href = `${ApiUrl}/auth/google`;
};

if (isLoggedIn) {
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/components/Profile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ const Profile = () => {
const [profilePicture, setProfilePicture] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
const ApiUrl = process.env.NODE_ENV === 'production'
? 'https://agrotech-ai-11j3.onrender.com'
: 'http://localhost:8080';


useEffect(() => {
const token = localStorage.getItem('auth');
if (token) {
const { userId } = JSON.parse(atob(token.split('.')[1]));
axios.get(`https://agro-tech-ai-backend-teal.vercel.app/api/users/${userId}`, {
axios.get(`${ApiUrl}/api/users/${userId}`, {
headers: {
Authorization: `Bearer ${token}`,
}
Expand Down Expand Up @@ -56,7 +60,7 @@ const Profile = () => {
const token = localStorage.getItem('auth');
const { userId } = JSON.parse(atob(token.split('.')[1]));

axios.put(`https://agro-tech-ai-backend-teal.vercel.app/api/users/${userId}`, formData, {
axios.put(`${ApiUrl}/api/users/${userId}`, formData, {
headers: {
Authorization: `Bearer ${token}`,
}
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/components/SignUpPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const SignUpPage = () => {
const [isNumber, setIsNumber] = useState(false);
const [isSpecialChar, setIsSpecialChar] = useState(false);
const [isMinLength, setIsMinLength] = useState(false);
const ApiUrl = process.env.NODE_ENV === 'production'
? 'https://agrotech-ai-11j3.onrender.com'
: 'http://localhost:8080';

const validatePassword = (input) => {
setPassword(input);
Expand Down Expand Up @@ -52,7 +55,7 @@ const SignUpPage = () => {

try {
const response = await axios.post(
"https://agro-tech-ai-backend-teal.vercel.app/auth/signup",
`${ApiUrl}/auth/signup`,
{
firstName,
lastName,
Expand All @@ -70,7 +73,7 @@ const SignUpPage = () => {
}
};
const handleGoogleSignIn = () => {
window.location.href = "https://agro-tech-ai-backend-teal.vercel.app/auth/google";
window.location.href = `${ApiUrl}/auth/google`;
};

return (
Expand Down

0 comments on commit 0be3710

Please sign in to comment.