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.

This commit is contained in:
Torsten Schulz (local)
2026-05-15 09:11:43 +02:00
parent 52719d5625
commit 58dd657ac1
4 changed files with 22 additions and 8 deletions

View File

@@ -76,7 +76,14 @@ class OAuthController {
return res.redirect(`${target}?${params.toString()}`); 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) { } catch (callbackError) {
console.error('Google OAuth Callback-Verarbeitung fehlgeschlagen:', callbackError); console.error('Google OAuth Callback-Verarbeitung fehlgeschlagen:', callbackError);
return res.redirect(`${process.env.FRONTEND_URL || 'http://localhost:5010'}/login?error=oauth_failed`); return res.redirect(`${process.env.FRONTEND_URL || 'http://localhost:5010'}/login?error=oauth_failed`);
@@ -169,4 +176,3 @@ class OAuthController {
module.exports = new OAuthController(); module.exports = new OAuthController();

View File

@@ -44,12 +44,12 @@ const password = ref('')
const linking = ref(false) const linking = ref(false)
const errorMessage = ref('') const errorMessage = ref('')
async function finishLogin(token) { async function finishLogin(token, redirectTarget = '/') {
authStore.saveToken(token) authStore.saveToken(token)
await authStore.fetchCurrentUser() await authStore.fetchCurrentUser()
status.value = 'Login erfolgreich! Sie werden weitergeleitet...' status.value = 'Login erfolgreich! Sie werden weitergeleitet...'
setTimeout(() => { setTimeout(() => {
router.push('/') router.push(redirectTarget)
}, 1000) }, 1000)
} }
@@ -71,7 +71,7 @@ async function linkExistingAccount() {
throw new Error(result.error || 'Verknüpfung fehlgeschlagen') throw new Error(result.error || 'Verknüpfung fehlgeschlagen')
} }
pendingToken.value = '' pendingToken.value = ''
await finishLogin(result.token) await finishLogin(result.token, '/settings/profile?oauthLinked=google')
} catch (error) { } catch (error) {
errorMessage.value = error.message || 'Verknüpfung fehlgeschlagen' errorMessage.value = error.message || 'Verknüpfung fehlgeschlagen'
} finally { } finally {
@@ -83,6 +83,7 @@ onMounted(async () => {
const token = route.query.token const token = route.query.token
const error = route.query.error const error = route.query.error
const pending = route.query.pending const pending = route.query.pending
const linked = route.query.linked
if (error) { if (error) {
status.value = 'OAuth-Login fehlgeschlagen' status.value = 'OAuth-Login fehlgeschlagen'
@@ -101,7 +102,7 @@ onMounted(async () => {
if (token) { if (token) {
try { try {
await finishLogin(token) await finishLogin(token, linked ? '/settings/profile?oauthLinked=google' : '/')
} catch (err) { } catch (err) {
status.value = 'Fehler beim Login' status.value = 'Fehler beim Login'
setTimeout(() => { setTimeout(() => {
@@ -180,4 +181,3 @@ onMounted(async () => {
} }
</style> </style>

View File

@@ -125,12 +125,15 @@
<script setup> <script setup>
import { ref, computed, onMounted } from 'vue' import { ref, computed, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useAuthStore } from '../stores/authStore' import { useAuthStore } from '../stores/authStore'
import { useModal } from '../composables/useModal' import { useModal } from '../composables/useModal'
import Modal from '../components/Modal.vue' import Modal from '../components/Modal.vue'
import { API_BASE_URL } from '@/config/api' import { API_BASE_URL } from '@/config/api'
const API_URL = API_BASE_URL const API_URL = API_BASE_URL
const route = useRoute()
const router = useRouter()
const authStore = useAuthStore() const authStore = useAuthStore()
const availableStates = ref([]) const availableStates = ref([])
const identities = ref([]) const identities = ref([])
@@ -305,6 +308,11 @@ onMounted(async () => {
loadProfile(), loadProfile(),
loadIdentities() loadIdentities()
]) ])
if (route.query.oauthLinked === 'google') {
await alert('Google-Konto wurde erfolgreich verknüpft', 'Erfolg')
router.replace('/settings/profile')
}
}) })
</script> </script>

View File

@@ -47,7 +47,7 @@ data class OAuthIdentitiesResponse(
data class OAuthIdentityDto( data class OAuthIdentityDto(
val provider: String, val provider: String,
val identity: String? = null, val identity: String? = null,
val id: String? = null, val id: Int? = null,
) )
@Serializable @Serializable