Fix login authentication flow and improve proxy configuration
All checks were successful
Build And Push Image / docker (push) Successful in 2m50s
All checks were successful
Build And Push Image / docker (push) Successful in 2m50s
- Refactor login page to use auth composable for better state management - Update nginx proxy settings with proper timeouts and buffering - Improve PWA service worker caching strategy for API calls - Add debug files and documentation for login troubleshooting
This commit is contained in:
@@ -122,8 +122,10 @@ definePageMeta({
|
||||
layout: false
|
||||
});
|
||||
|
||||
// Use the auth composable
|
||||
const { user, login, loading: authLoading, error: authError, checkAuth } = useAuth();
|
||||
|
||||
// Check if user is already authenticated
|
||||
const { user } = useAuth();
|
||||
if (user.value) {
|
||||
await navigateTo('/dashboard');
|
||||
}
|
||||
@@ -137,7 +139,6 @@ const credentials = ref({
|
||||
|
||||
const showPassword = ref(false);
|
||||
const showForgotPassword = ref(false);
|
||||
const loading = ref(false);
|
||||
const loginError = ref('');
|
||||
const errors = ref({
|
||||
username: '',
|
||||
@@ -147,6 +148,7 @@ const errors = ref({
|
||||
const loginForm = ref();
|
||||
|
||||
// Computed
|
||||
const loading = computed(() => authLoading.value);
|
||||
const isFormValid = computed(() => {
|
||||
return credentials.value.username.length > 0 &&
|
||||
credentials.value.password.length > 0 &&
|
||||
@@ -174,33 +176,22 @@ const validateForm = () => {
|
||||
const handleLogin = async () => {
|
||||
if (!validateForm()) return;
|
||||
|
||||
loading.value = true;
|
||||
loginError.value = '';
|
||||
|
||||
try {
|
||||
const response = await $fetch<{
|
||||
success: boolean;
|
||||
redirectTo?: string;
|
||||
user?: any;
|
||||
}>('/api/auth/direct-login', {
|
||||
method: 'POST',
|
||||
body: {
|
||||
username: credentials.value.username,
|
||||
password: credentials.value.password,
|
||||
rememberMe: credentials.value.rememberMe
|
||||
}
|
||||
const result = await login({
|
||||
username: credentials.value.username,
|
||||
password: credentials.value.password,
|
||||
rememberMe: credentials.value.rememberMe
|
||||
});
|
||||
|
||||
if (response.success) {
|
||||
// Force a page reload to ensure the session cookie is properly read
|
||||
// This is more reliable than trying to update the auth state manually
|
||||
window.location.href = response.redirectTo || '/dashboard';
|
||||
if (!result.success) {
|
||||
loginError.value = result.error || 'Login failed. Please check your credentials and try again.';
|
||||
}
|
||||
// If successful, the login method will handle the redirect
|
||||
} catch (error: any) {
|
||||
console.error('Login error:', error);
|
||||
loginError.value = error.data?.message || 'Login failed. Please check your credentials and try again.';
|
||||
} finally {
|
||||
loading.value = false;
|
||||
loginError.value = authError.value || 'Login failed. Please check your credentials and try again.';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user