This commit introduces a complete user authentication system, replacing the previous placeholder login page. The new flow includes signup, login, and OTP verification, all integrated with backend webhooks. - Adds `AuthPage` to manage the view state between login, signup, and OTP forms. - Implements `LoginForm` with support for both email and WhatsApp credentials. - Implements `SignupForm` with password strength and confirmation validation. - Adds `OtpForm` for two-factor verification after a successful signup. - Integrates `axios` for making API calls to the backend webhooks. - Updates styling with a new background, custom brand colors, and the Poppins font. BREAKING CHANGE: The `LoginPage` component has been deleted and is replaced by the new `AuthPage` component. Any imports of `LoginPage` must be updated.
42 lines
1.5 KiB
JavaScript
42 lines
1.5 KiB
JavaScript
import React, { useState, useCallback } from 'react';
|
|
import LoginForm from './LoginForm';
|
|
import SignupForm from './SignupForm';
|
|
import OtpForm from './OtpForm';
|
|
import ForgotPasswordForm from './ForgotPasswordForm';
|
|
import ResetPasswordForm from './ResetPasswordForm';
|
|
|
|
const AuthPage = () => {
|
|
const [view, setView] = useState('login'); // 'login', 'signup', 'otp', 'forgotPassword', 'resetPassword'
|
|
|
|
const showSignup = useCallback(() => setView('signup'), []);
|
|
const showLogin = useCallback(() => setView('login'), []);
|
|
const showOtp = useCallback(() => setView('otp'), []);
|
|
const showForgotPassword = useCallback(() => setView('forgotPassword'), []);
|
|
const showResetPassword = useCallback(() => setView('resetPassword'), []);
|
|
|
|
const renderForm = () => {
|
|
switch (view) {
|
|
case 'signup':
|
|
return <SignupForm toggleForm={showLogin} onSuccess={showOtp} />;
|
|
case 'otp':
|
|
return <OtpForm onSuccess={showLogin} />;
|
|
case 'forgotPassword':
|
|
return <ForgotPasswordForm showLogin={showLogin} showReset={showResetPassword} />;
|
|
case 'resetPassword':
|
|
return <ResetPasswordForm showLogin={showLogin} />;
|
|
case 'login':
|
|
default:
|
|
return <LoginForm toggleForm={showSignup} showForgotPassword={showForgotPassword} />;
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="min-h-screen flex items-center justify-center p-4">
|
|
<div className="w-full max-w-md p-8 space-y-6 bg-black/30 backdrop-blur-xl rounded-2xl shadow-2xl">
|
|
{renderForm()}
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default AuthPage; |