auth logging
This commit is contained in:
@@ -135,7 +135,9 @@ export const AuthProvider = ({ children }) => {
|
|||||||
dispatch({ type: actionTypes.SET_LOADING, payload: true });
|
dispatch({ type: actionTypes.SET_LOADING, payload: true });
|
||||||
dispatch({ type: actionTypes.CLEAR_ERROR });
|
dispatch({ type: actionTypes.CLEAR_ERROR });
|
||||||
|
|
||||||
|
console.log('Attempting login...', credentials.email);
|
||||||
const response = await authAPI.login(credentials);
|
const response = await authAPI.login(credentials);
|
||||||
|
console.log('Login response:', response.data);
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: actionTypes.LOGIN_SUCCESS,
|
type: actionTypes.LOGIN_SUCCESS,
|
||||||
@@ -145,7 +147,8 @@ export const AuthProvider = ({ children }) => {
|
|||||||
toast.success('Welcome back!');
|
toast.success('Welcome back!');
|
||||||
return { success: true };
|
return { success: true };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage = error.response?.data?.message || 'Login failed. Please try again.';
|
console.error('Login error:', error);
|
||||||
|
const errorMessage = error.response?.data?.message || error.message || 'Login failed. Please try again.';
|
||||||
dispatch({ type: actionTypes.SET_ERROR, payload: errorMessage });
|
dispatch({ type: actionTypes.SET_ERROR, payload: errorMessage });
|
||||||
toast.error(errorMessage);
|
toast.error(errorMessage);
|
||||||
return { success: false, error: errorMessage };
|
return { success: false, error: errorMessage };
|
||||||
@@ -161,7 +164,9 @@ export const AuthProvider = ({ children }) => {
|
|||||||
// Filter out frontend-only fields before sending to backend
|
// Filter out frontend-only fields before sending to backend
|
||||||
const { confirmPassword, agreeTerms, ...backendData } = userData;
|
const { confirmPassword, agreeTerms, ...backendData } = userData;
|
||||||
|
|
||||||
|
console.log('Attempting registration...', backendData.email);
|
||||||
const response = await authAPI.register(backendData);
|
const response = await authAPI.register(backendData);
|
||||||
|
console.log('Registration response:', response.data);
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: actionTypes.LOGIN_SUCCESS,
|
type: actionTypes.LOGIN_SUCCESS,
|
||||||
|
|||||||
@@ -21,10 +21,15 @@ const Login = () => {
|
|||||||
} = useForm();
|
} = useForm();
|
||||||
|
|
||||||
const onSubmit = async (data) => {
|
const onSubmit = async (data) => {
|
||||||
|
console.log('Login form submitted:', data.email);
|
||||||
const result = await login(data);
|
const result = await login(data);
|
||||||
|
console.log('Login result:', result);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
|
console.log('Login successful, navigating to:', from);
|
||||||
navigate(from, { replace: true });
|
navigate(from, { replace: true });
|
||||||
} else {
|
} else {
|
||||||
|
console.log('Login failed, showing error:', result.error);
|
||||||
setError('root', {
|
setError('root', {
|
||||||
type: 'manual',
|
type: 'manual',
|
||||||
message: result.error
|
message: result.error
|
||||||
|
|||||||
@@ -21,10 +21,15 @@ const Register = () => {
|
|||||||
const password = watch('password');
|
const password = watch('password');
|
||||||
|
|
||||||
const onSubmit = async (data) => {
|
const onSubmit = async (data) => {
|
||||||
|
console.log('Register form submitted:', data.email);
|
||||||
const result = await registerUser(data);
|
const result = await registerUser(data);
|
||||||
|
console.log('Register result:', result);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
|
console.log('Registration successful, navigating to dashboard');
|
||||||
navigate('/dashboard');
|
navigate('/dashboard');
|
||||||
} else {
|
} else {
|
||||||
|
console.log('Registration failed, showing error:', result.error);
|
||||||
setError('root', {
|
setError('root', {
|
||||||
type: 'manual',
|
type: 'manual',
|
||||||
message: result.error
|
message: result.error
|
||||||
|
|||||||
Reference in New Issue
Block a user