From 58dd657ac1ffd52df9515700f388eee1eb5c8ebf Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Fri, 15 May 2026 09:11:43 +0200 Subject: [PATCH] Enhance OAuth flow by updating redirect handling in OAuthController and improving login process in OAuthCallback. Adjust Profile view to notify users upon successful Google account linking. Update mobile app to reflect changes in OAuth identity management with updated data types. This improves user experience and feedback during the OAuth process. --- backend/src/controllers/OAuthController.js | 10 ++++++++-- frontend/src/views/OAuthCallback.vue | 10 +++++----- frontend/src/views/Profile.vue | 8 ++++++++ .../de/tsschulz/timeclock/data/api/SettingsDtos.kt | 2 +- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/backend/src/controllers/OAuthController.js b/backend/src/controllers/OAuthController.js index b351b0a..d937440 100644 --- a/backend/src/controllers/OAuthController.js +++ b/backend/src/controllers/OAuthController.js @@ -76,7 +76,14 @@ class OAuthController { return res.redirect(`${target}?${params.toString()}`); } - return res.redirect(`${target}?token=${encodeURIComponent(authResult.token)}`); + const params = new URLSearchParams({ + token: authResult.token + }); + if (state.mode === 'link') { + params.set('linked', result.provider); + } + + return res.redirect(`${target}?${params.toString()}`); } catch (callbackError) { console.error('Google OAuth Callback-Verarbeitung fehlgeschlagen:', callbackError); return res.redirect(`${process.env.FRONTEND_URL || 'http://localhost:5010'}/login?error=oauth_failed`); @@ -169,4 +176,3 @@ class OAuthController { module.exports = new OAuthController(); - diff --git a/frontend/src/views/OAuthCallback.vue b/frontend/src/views/OAuthCallback.vue index 346a743..1328d76 100644 --- a/frontend/src/views/OAuthCallback.vue +++ b/frontend/src/views/OAuthCallback.vue @@ -44,12 +44,12 @@ const password = ref('') const linking = ref(false) const errorMessage = ref('') -async function finishLogin(token) { +async function finishLogin(token, redirectTarget = '/') { authStore.saveToken(token) await authStore.fetchCurrentUser() status.value = 'Login erfolgreich! Sie werden weitergeleitet...' setTimeout(() => { - router.push('/') + router.push(redirectTarget) }, 1000) } @@ -71,7 +71,7 @@ async function linkExistingAccount() { throw new Error(result.error || 'Verknüpfung fehlgeschlagen') } pendingToken.value = '' - await finishLogin(result.token) + await finishLogin(result.token, '/settings/profile?oauthLinked=google') } catch (error) { errorMessage.value = error.message || 'Verknüpfung fehlgeschlagen' } finally { @@ -83,6 +83,7 @@ onMounted(async () => { const token = route.query.token const error = route.query.error const pending = route.query.pending + const linked = route.query.linked if (error) { status.value = 'OAuth-Login fehlgeschlagen' @@ -101,7 +102,7 @@ onMounted(async () => { if (token) { try { - await finishLogin(token) + await finishLogin(token, linked ? '/settings/profile?oauthLinked=google' : '/') } catch (err) { status.value = 'Fehler beim Login' setTimeout(() => { @@ -180,4 +181,3 @@ onMounted(async () => { } - diff --git a/frontend/src/views/Profile.vue b/frontend/src/views/Profile.vue index f9effde..8c0a1f8 100644 --- a/frontend/src/views/Profile.vue +++ b/frontend/src/views/Profile.vue @@ -125,12 +125,15 @@ diff --git a/mobile-app/composeApp/src/main/kotlin/de/tsschulz/timeclock/data/api/SettingsDtos.kt b/mobile-app/composeApp/src/main/kotlin/de/tsschulz/timeclock/data/api/SettingsDtos.kt index 0fe4354..3111de4 100644 --- a/mobile-app/composeApp/src/main/kotlin/de/tsschulz/timeclock/data/api/SettingsDtos.kt +++ b/mobile-app/composeApp/src/main/kotlin/de/tsschulz/timeclock/data/api/SettingsDtos.kt @@ -47,7 +47,7 @@ data class OAuthIdentitiesResponse( data class OAuthIdentityDto( val provider: String, val identity: String? = null, - val id: String? = null, + val id: Int? = null, ) @Serializable