From 0d83118938d70b4c92120a69ca7deacbf0f2c1af Mon Sep 17 00:00:00 2001 From: aryabenade Date: Thu, 23 Apr 2026 13:31:46 +0530 Subject: [PATCH] remove from local and session storage when signing out --- src/components/LoginModal.tsx | 21 +-- src/components/RegisterPage.tsx | 296 ++++++++++++++++++-------------- src/context/AuthContext.tsx | 2 + 3 files changed, 178 insertions(+), 141 deletions(-) diff --git a/src/components/LoginModal.tsx b/src/components/LoginModal.tsx index 0fa4523..11413ff 100644 --- a/src/components/LoginModal.tsx +++ b/src/components/LoginModal.tsx @@ -21,7 +21,6 @@ export function LoginModal({ isOpen, onClose }: LoginModalProps) { const [countdown, setCountdown] = useState(0); const [helperText, setHelperText] = useState(''); const [error, setError] = useState(''); - const [showRegisterModal, setShowRegisterModal] = useState(false); const { login } = useAuth(); const navigate = useNavigate() @@ -148,17 +147,19 @@ export function LoginModal({ isOpen, onClose }: LoginModalProps) { otp: otpString }).unwrap(); - const userData = { - userId: response?.user?.id, - email: response?.email || email, - name: response?.name || email.split('@')[0].charAt(0).toUpperCase() + email.split('@')[0].slice(1), - accessToken: response?.accessToken, - }; - - login(userData); - if (!response?.data?.userExists) { + + if (!response?.userExists) { + localStorage.setItem("userEmail",email) navigate("/register") } else { + const userData = { + userId: response?.user?.id, + email: response?.email || email, + name: response?.name || email.split('@')[0].charAt(0).toUpperCase() + email.split('@')[0].slice(1), + accessToken: response?.accessToken, + }; + + login(userData); toast.success("User Logged in successfully") } onClose(); diff --git a/src/components/RegisterPage.tsx b/src/components/RegisterPage.tsx index 9908650..f6ea833 100644 --- a/src/components/RegisterPage.tsx +++ b/src/components/RegisterPage.tsx @@ -7,14 +7,15 @@ import { useAuth } from '../context/AuthContext'; import Navbar from './Navbar'; import { Footer } from './Footer'; import { useNavigate } from 'react-router-dom'; +import { Label } from './ui/label'; export default function RegisterPage() { - const { login, user } = useAuth(); - + const { login } = useAuth(); + const email = localStorage.getItem("userEmail") const [formData, setFormData] = useState({ firstName: '', lastName: '', - emailAddress: user?.email ?? "", + emailAddress: email ?? "", isdCode: '', mobileNumber: '', address1: '', @@ -32,9 +33,6 @@ export default function RegisterPage() { const [register, { isLoading: isRegistering }] = useRegisterMutation(); - const emailAddress = user?.email - - const handleInputChange = (field: string, value: string) => { setFormData(prev => ({ ...prev, [field]: value })); }; @@ -68,8 +66,8 @@ export default function RegisterPage() { name: response?.name || formData.emailAddress.split('@')[0].charAt(0).toUpperCase() + formData.emailAddress.split('@')[0].slice(1), accessToken: response?.accessToken, }; - login(userData); + localStorage.removeItem("userEmail") navigate("/") } catch (err: any) { const msg = err?.data?.message || 'Registration failed'; @@ -81,146 +79,182 @@ export default function RegisterPage() { }; return ( -
- {/* Navbar */} - - {/* Main Content */} -
+
+ {/* Navbar */} + -
+ {/* Main Content */} +
+
- {/* Header */} -
-

- Create Account -

-

- Register to get started with City Cards -

+ {/* Header */} +
+

+ Create Account +

+

+ Register to get started with City Cards +

+
+ + {/* Form Container */} +
+ + {/* Personal Info */} +
+

+ Personal Information +

+ +
+
+ + handleInputChange('firstName', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" + /> +
+ +
+ + handleInputChange('lastName', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" + /> +
- {/* Form Container */} -
- - {/* Personal Info */} -
-

- Personal Information -

- -
- handleInputChange('firstName', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl" - /> - handleInputChange('lastName', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl" - /> -
+
+ + handleInputChange('emailAddress', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" + /> +
+
+
+ handleInputChange('emailAddress', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl" + id="isdCode" + placeholder="example: +91" + value={formData.isdCode} + onChange={(e) => handleInputChange('isdCode', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" /> - -
- handleInputChange('isdCode', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl" - /> -
- handleInputChange('mobileNumber', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl" - /> -
-
- {/* Address */} -
-

- Address Information -

- +
+ handleInputChange('address1', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl" + id="mobileNumber" + value={formData.mobileNumber} + onChange={(e) => handleInputChange('mobileNumber', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" /> - - handleInputChange('address2', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl" - /> - -
- handleInputChange('city', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl" - /> - handleInputChange('state', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl" - /> -
- -
- handleInputChange('country', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl" - /> - handleInputChange('postalCode', e.target.value)} - className="h-12 bg-gray-50 border-0 rounded-xl" - /> -
- - {helperText && ( -

{helperText}

- )} - - -
-
- {/* Footer */} -
-
-
+ {/* Address */} +
+

+ Address Information +

+
+ + handleInputChange('address1', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" + /> +
+ +
+ + handleInputChange('address2', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" + /> +
+ +
+
+ + handleInputChange('city', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" + /> +
+ +
+ + handleInputChange('state', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" + /> +
+
+ +
+
+ + handleInputChange('country', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" + /> +
+ +
+ + handleInputChange('postalCode', e.target.value)} + className="h-12 bg-gray-50 border-0 rounded-xl mt-1" + /> +
+
+
+ + {helperText && ( +

{helperText}

+ )} + + + +
+
+ + {/* Footer */} +
+
+
); } \ No newline at end of file diff --git a/src/context/AuthContext.tsx b/src/context/AuthContext.tsx index 50dba2a..b3cdda3 100644 --- a/src/context/AuthContext.tsx +++ b/src/context/AuthContext.tsx @@ -40,6 +40,8 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => { localStorage.removeItem("user") localStorage.removeItem("accessToken") localStorage.removeItem("userId") + localStorage.removeItem("userEmail") + sessionStorage.removeItem("citySelected") navigate("/") }