All files / src/views LoginView.vue

0% Statements 0/41
100% Branches 1/1
100% Functions 1/1
0% Lines 0/41

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58                                                                                                                   
<script setup lang="ts">
import { onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { LogIn } from 'lucide-vue-next'
import { useAuthStore } from '@/stores/auth.store'
 
const router = useRouter()
const route = useRoute()
const authStore = useAuthStore()
 
// Get return URL from query params
const returnUrl = (route.query.returnUrl as string) || '/dashboard'
 
// Redirect to Keycloak login
const loginWithKeycloak = async () => {
  try {
    await authStore.login(returnUrl)
  } catch (err: any) {
    console.error('Login redirect failed:', err)
  }
}
 
// Auto-redirect if already authenticated
onMounted(() => {
  if (authStore.isAuthenticated) {
    router.push(returnUrl)
  }
})
</script>
 
<template>
  <div>
    <h2 class="text-2xl font-bold text-center mb-6 text-gray-800">
      {{ $t('auth.login.title') }}
    </h2>
 
    <!-- Info Text -->
    <div class="mb-6 text-center text-gray-600">
      <p>{{ $t('auth.login.keycloakInfo') }}</p>
    </div>
 
    <!-- Keycloak Login Button -->
    <button
      @click="loginWithKeycloak"
      type="button"
      class="w-full bg-primary hover:bg-primary/90 text-white py-3 rounded-lg font-medium flex items-center justify-center gap-2 transition"
    >
      <LogIn :size="20" />
      {{ $t('auth.login.keycloakButton') }}
    </button>
 
    <!-- Info about registration -->
    <div class="mt-6 text-center text-sm text-gray-600">
      <p>{{ $t('auth.login.noAccount') }}</p>
    </div>
  </div>
</template>