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