Skip to content

Commit 43ef22b

Browse files
committed
Enhance authentication flow: add success message to LoginForm, pre-fill email from SignupForm, and redirect with message after registration
1 parent 019288f commit 43ef22b

4 files changed

Lines changed: 36 additions & 7 deletions

File tree

8 KB
Binary file not shown.

planventure-client/src/components/auth/LoginForm.jsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from 'react';
1+
import { useState, useEffect } from 'react';
22
import { useNavigate, useLocation } from 'react-router-dom';
33
import {
44
Box,
@@ -29,6 +29,21 @@ const LoginForm = () => {
2929
password: ''
3030
});
3131

32+
// Add state for success message
33+
const [successMessage, setSuccessMessage] = useState(
34+
location.state?.message || ''
35+
);
36+
37+
// Pre-fill email if coming from signup
38+
useEffect(() => {
39+
if (location.state?.email) {
40+
setFormData(prev => ({
41+
...prev,
42+
email: location.state.email
43+
}));
44+
}
45+
}, [location.state]);
46+
3247
const validateEmail = (email) => {
3348
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
3449
if (!email) return 'Email is required';
@@ -112,6 +127,12 @@ const LoginForm = () => {
112127
Login to Planventure
113128
</Typography>
114129

130+
{successMessage && (
131+
<Alert severity="success" sx={{ mb: 2 }}>
132+
{successMessage}
133+
</Alert>
134+
)}
135+
115136
{error && (
116137
<Alert severity="error" sx={{ mb: 2 }}>
117138
{error}

planventure-client/src/components/auth/SignupForm.jsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,21 @@ const SignupForm = () => {
9292
password: formData.password
9393
};
9494

95-
const data = await api.auth.register(userData);
95+
const response = await api.auth.register(userData);
96+
console.log('Signup response:', response); // Debug log
9697

97-
if(data.accessToken) {
98-
setIsAuthenticated(true);
99-
navigate('/dashboard', { replace: true });
100-
}
98+
// Don't check for accessToken, just redirect after successful registration
99+
navigate('/login', {
100+
replace: true,
101+
state: {
102+
message: 'Registration successful! Please log in.',
103+
email: formData.email
104+
}
105+
});
101106

102107
} catch (err) {
103-
setError(err.message);
108+
console.error('Signup error:', err); // Debug log
109+
setError(err.message || 'Registration failed. Please try again.');
104110
} finally {
105111
setIsLoading(false);
106112
}

planventure-client/src/pages/Dashboard.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useNavigate } from 'react-router-dom';
12
import { Box, Typography, Grid, Paper, Button } from '@mui/material';
23
import { Add as AddIcon } from '@mui/icons-material';
34
import TripList from '../components/trips/TripList';
@@ -6,6 +7,7 @@ import travelingSvg from '../assets/undraw_traveling_yhxq.svg';
67

78
const Dashboard = () => {
89
const { user } = useAuth();
10+
const navigate = useNavigate();
911

1012
const WelcomeMessage = () => (
1113
<Box

0 commit comments

Comments
 (0)