All files / src/views SignupPage.vue

97.72% Statements 43/44
84.37% Branches 27/32
90% Functions 9/10
97.72% Lines 43/44

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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172  12x       48x   12x         8x     1x     1x     6x             1x     6x             1x 1x     6x                                                   1x     2x                                                 12x 12x 12x   12x 12x 12x 12x 12x 12x 12x 12x     6x 6x   6x 6x     5x   1x 1x     4x     1x   6x         2x 2x   2x 2x 1x 1x   1x   2x                                                        
<template>
  <AuthLayout
    :presentation-title="t('auth.presentationTitleSignup')"
    :presentation-subtitle="t('auth.presentationSubtitleSignup')"
  >
    <span>{{ t('auth.alreadyHaveAccount') }}</span>
    <router-link to="/login" class="btn btn-secondary shadow p-2 my-3 w-100">
      {{ t('auth.signIn') }}
    </router-link>
 
    <form
      class="signin-form"
      @submit.prevent="needsConfirmation ? handleConfirm() : handleSignup()"
    >
      <hr class="w-100" />
      <span class="mb-2">{{ t('auth.createFreeAccount') }}</span>
 
      <template v-if="!needsConfirmation">
        <label for="name">{{ t('auth.fullName') }}</label>
        <input
          id="name"
          v-model="name"
          class="w-100"
          type="text"
          name="name"
          autocomplete="name"
          required
        />
        <label for="email">{{ t('auth.email') }}</label>
        <input
          id="email"
          v-model="email"
          class="w-100"
          type="email"
          name="email"
          autocomplete="email"
          required
        />
        <label for="password">{{ t('auth.password') }}</label>
        <div class="password-wrapper">
          <input
            id="password"
            v-model="password"
            class="w-100"
            :type="showPassword ? 'text' : 'password'"
            name="password"
            autocomplete="new-password"
            required
            minlength="8"
          />
          <button
            type="button"
            class="password-toggle"
            :aria-label="showPassword ? t('auth.hidePassword') : t('auth.showPassword')"
            @click="showPassword = !showPassword"
          >
            <FontAwesomeIcon :icon="showPassword ? 'eye-slash' : 'eye'" />
          </button>
        </div>
        <button class="btn btn-success shadow p-2 my-3" :disabled="loading">
          {{ t('auth.signUp') }}
        </button>
      </template>
 
      <template v-else>
        <div class="alert alert-info" role="alert">
          {{ t('auth.pleaseCheckEmail') }}
        </div>
        <label for="code">{{ t('auth.confirmationCode') }}</label>
        <input
          id="code"
          v-model="confirmationCode"
          class="w-100"
          type="text"
          name="code"
          required
        />
        <button class="btn btn-success shadow p-2 my-3" :disabled="loading">
          {{ t('auth.confirm') }}
        </button>
      </template>
 
      <div v-if="error" class="alert alert-danger" role="alert">
        {{ error }}
      </div>
    </form>
  </AuthLayout>
</template>
 
<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
import { useUILanguage } from '@/composables/useUILanguage'
import AuthLayout from '@/components/AuthLayout.vue'
 
const router = useRouter()
const authStore = useAuthStore()
const { t } = useUILanguage()
 
const name = ref('')
const email = ref('')
const password = ref('')
const showPassword = ref(false)
const confirmationCode = ref('')
const needsConfirmation = ref(false)
const loading = ref(false)
const error = ref('')
 
async function handleSignup() {
  loading.value = true
  error.value = ''
 
  try {
    const result = await authStore.register(email.value, password.value, name.value)
 
    // Check if user was auto-confirmed (e.g., @browsway.com emails)
    if (result.isSignUpComplete) {
      // Auto-confirmed: login directly
      await authStore.login(email.value, password.value)
      router.push('/')
    } else {
      // Needs email confirmation
      needsConfirmation.value = true
    }
  } catch (err: any) {
    error.value = err.message || 'Signup failed'
  } finally {
    loading.value = false
  }
}
 
async function handleConfirm() {
  loading.value = true
  error.value = ''
 
  try {
    await authStore.confirm(email.value, confirmationCode.value)
    await authStore.login(email.value, password.value)
    router.push('/')
  } catch (err: any) {
    error.value = err.message || 'Confirmation failed'
  } finally {
    loading.value = false
  }
}
</script>
 
<style scoped>
.password-wrapper {
  position: relative;
  width: 100%;
}
 
.password-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: #666;
  padding: 0 4px;
  line-height: 1;
}
 
.password-toggle:hover {
  color: #333;
}
</style>