feat(auth): enhance login flow with notifications and path normalization
- add success notification on successful login - show error notification with detailed message on login failure - normalize API paths to prevent double slashes and trailing slashes - redirect to login page only if not on login request or page
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
Center,
|
||||
Box
|
||||
} from '@mantine/core';
|
||||
import { notifications } from '@mantine/notifications';
|
||||
import { IconAlertCircle, IconBrandWhatsapp } from '@tabler/icons-react';
|
||||
import { useAuthStore } from '../stores/authStore';
|
||||
|
||||
@@ -28,10 +29,24 @@ export default function LoginPage() {
|
||||
|
||||
try {
|
||||
await login(username, password);
|
||||
notifications.show({
|
||||
title: 'Login successful',
|
||||
message: 'Welcome back!',
|
||||
color: 'green',
|
||||
});
|
||||
navigate('/');
|
||||
} catch (err) {
|
||||
// Error is handled in the store
|
||||
console.error('Login failed:', err);
|
||||
} catch (err: any) {
|
||||
const responseData = err?.response?.data;
|
||||
const notificationMessage =
|
||||
responseData?.message ||
|
||||
(typeof responseData === 'string' ? responseData.trim() : '') ||
|
||||
'Invalid username or password';
|
||||
|
||||
notifications.show({
|
||||
title: 'Login failed',
|
||||
message: notificationMessage,
|
||||
color: 'red',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user