All files / src/components/organisms LoginForm.vue

75.55% Statements 34/45
72.72% Branches 8/11
80% Functions 4/5
75.55% Lines 34/45

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  1x 1x 1x 1x 1x 1x 1x 1x   1x 1x   1x 1x   1x 1x         1x 1x 1x                   1x                   1x 1x 1x                     1x 1x 1x 1x 1x     1x   1x                 1x 1x 1x 1x 1x     1x                    
<template>
  <div>
    <h2>ログイン</h2>
    <form @submit.prevent="handleLogin">
      <input type="email" v-model="email" placeholder="メールアドレス" required />
      <input type="password" v-model="password" placeholder="パスワード" required />
      <button type="submit">ログイン</button>
    </form>
    <p>
      アカウントを持っていませんか?
      <a href="#" @click.prevent="handleRegister">登録する</a>
    </p>
 
    <hr />
    <button @click="handleGoogleLogin">Googleでログイン</button>
 
    <p v-if="message" class="error">{{ message }}</p>
  </div>
</template>
 
<script setup lang="ts">
// region Dependency Injection
import {ref} from 'vue';
import {loginWithEmail, loginWithGoogle, registerWithEmail} from '@/services/authService';
import {useRouter} from 'vue-router';
// endregion Dependency Injection
 
// region Component Import
// endregion Component Import
 
// region interface
// endregion interface
 
// region constants
const router = useRouter()
// endregion constants
 
// region props
// endregion props
 
// region variable
// endregion variable
 
// region properties
const email = ref('');
const password = ref('');
const message = ref('');
// endregion properties
 
// region emits
// endregion emits
 
// region validator
// endregion validator
 
// region methods
// リンク用モーダル
const handleLogin = async () => {
  try {
    await loginWithEmail(email.value, password.value);
    await router.push({name: 'Dashboard'});
  } catch (e: any) {
    message.value = e.message;
  }
};
 
const handleRegister = async () => {
  try {
    await registerWithEmail(email.value, password.value);
    await router.push({name: 'Dashboard'});
  } catch (e: any) {
    message.value = e.message;
  }
};
 
const handleGoogleLogin = async () => {
  try {
    await loginWithGoogle();
    await router.push({name: 'Dashboard'});
  } catch (e: any) {
    message.value = e.message;
  }
};
// endregion methods
 
// region export
// endregion export
</script>
 
<style scoped>
 
</style>