Enhance login functionality in AuthController and AuthService; add optional action parameter to login method, execute corresponding actions post-login, and handle action warnings. Update frontend components to trigger data refresh on successful login and display warnings if actions fail. Adjust SQL query in TimeEntryService for improved grouping.

This commit is contained in:
Torsten Schulz (local)
2025-10-20 07:48:53 +02:00
parent e55f20367d
commit 648a94c4da
8 changed files with 261 additions and 14 deletions

View File

@@ -39,7 +39,9 @@
import { onMounted, onBeforeUnmount, ref, computed } from 'vue'
import { useTimeStore } from '../stores/timeStore'
import { useAuthStore } from '../stores/authStore'
import { API_BASE_URL } from '@/config/api'
const API_URL = API_BASE_URL
const timeStore = useTimeStore()
const authStore = useAuthStore()
const stats = ref({})
@@ -92,7 +94,7 @@ const fetchStats = async () => {
const fetchCurrentState = async () => {
try {
const response = await fetch('${API_URL}/time-entries/current-state', {
const response = await fetch(`${API_URL}/time-entries/current-state`, {
headers: authStore.getAuthHeaders()
})
@@ -108,7 +110,7 @@ const fetchCurrentState = async () => {
// Lade die aktuellen Worklog-Daten (nur einmal pro Minute)
const fetchWorklogData = async () => {
try {
const response = await fetch('${API_URL}/time-entries/running', {
const response = await fetch(`${API_URL}/time-entries/running`, {
headers: authStore.getAuthHeaders()
})
@@ -277,7 +279,7 @@ const handleAction = async (action) => {
try {
loading.value = true
const response = await fetch('${API_URL}/time-entries/clock', {
const response = await fetch(`${API_URL}/time-entries/clock`, {
method: 'POST',
headers: {
...authStore.getAuthHeaders(),
@@ -341,6 +343,14 @@ const rightButton = computed(() => {
}
})
// Event-Handler für Login
const handleLoginCompleted = async () => {
console.log('DEBUG: Login completed, lade Daten neu...')
await fetchCurrentState()
await fetchWorklogData()
await fetchStats()
}
onMounted(async () => {
// Initiales Laden
await fetchCurrentState()
@@ -359,11 +369,15 @@ onMounted(async () => {
updateCurrentlyWorkedTime()
updateOpenTime()
}, 500)
// Event-Listener für Login
window.addEventListener('login-completed', handleLoginCompleted)
})
onBeforeUnmount(() => {
if (dataFetchInterval) clearInterval(dataFetchInterval)
if (displayUpdateInterval) clearInterval(displayUpdateInterval)
window.removeEventListener('login-completed', handleLoginCompleted)
})
const displayRows = computed(() => {

View File

@@ -131,13 +131,26 @@ const handleLogin = async () => {
try {
error.value = ''
await authStore.login({
const result = await authStore.login({
email: loginForm.value.email,
password: loginForm.value.password
password: loginForm.value.password,
action: loginAction.value
})
// Nach erfolgreichem Login zum Dashboard
router.push('/')
// Event auslösen, damit StatusBox sich aktualisiert
window.dispatchEvent(new CustomEvent('login-completed'))
// Zeige Warnung, falls Aktion nicht ausgeführt werden konnte
if (result.actionWarning) {
error.value = result.actionWarning
// Trotzdem zum Dashboard weiterleiten (nach kurzer Verzögerung)
setTimeout(() => {
router.push('/')
}, 2000)
} else {
// Nach erfolgreichem Login zum Dashboard
router.push('/')
}
} catch (err) {
error.value = err.message || 'Login fehlgeschlagen. Bitte überprüfen Sie Ihre Eingaben.'
}

View File

@@ -190,6 +190,9 @@
<script setup>
import { ref, computed, onMounted, onBeforeUnmount } from 'vue'
import { useAuthStore } from '../stores/authStore'
import { API_BASE_URL } from '@/config/api'
const API_URL = API_BASE_URL
const authStore = useAuthStore()