Compare commits

...

3 Commits

Author SHA1 Message Date
Bastian Masanek f173a274e8 Integrate fetchCart function to refresh the cart upon user login 4 weeks ago
Bastian Masanek f00ce42f74 Handle 401 Error During Role Status Fetch in useActiveRole Composable 4 weeks ago
Bastian Masanek 1ea445bbfb Add AlertCircle Icon to Authentication Page 4 weeks ago
  1. 7
      app/composables/useActiveRole.ts
  2. 4
      app/composables/useAuth.ts
  3. 2
      app/pages/auth.vue

7
app/composables/useActiveRole.ts

@ -56,6 +56,13 @@ export function useActiveRole() {
return data
} catch (err: any) {
// 401 during session initialization is normal - watch() will retry successfully
if (err.statusCode === 401) {
console.debug('Role status fetch: Session not ready yet, will retry via watch()')
return null
}
// Other errors are real problems
console.error('Failed to fetch role status:', err)
error.value = 'Fehler beim Laden der Rollen'
throw err

4
app/composables/useAuth.ts

@ -12,6 +12,7 @@
export function useAuth() {
const { loggedIn, user, clear, fetch } = useUserSession()
const { fetchRoleStatus } = useActiveRole()
const { fetchCart } = useCart()
/**
* Login with email and password
@ -41,6 +42,9 @@ export function useAuth() {
// Fetch user roles immediately after login
await fetchRoleStatus()
// Refresh cart after login to show any existing items
await fetchCart()
// Redirect to products page or saved destination
const redirectAfterLogin = useCookie('redirect_after_login')
const destination = redirectAfterLogin.value || '/'

2
app/pages/auth.vue

@ -1,6 +1,8 @@
<!-- app/pages/auth.vue -->
<script setup lang="ts">
import { AlertCircle } from 'lucide-vue-next'
/**
* Combined Authentication Page
*

Loading…
Cancel
Save