サルでもわかるWEBプログラミング

フリーソフトのみでホームページ作成

ユーザ用ツール

サイト用ツール


17.nuxt.jsのvuexでパスワード制限:index.html


差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
17.nuxt.jsのvuexでパスワード制限:index.html [2019/02/08] – [新規Nuxt.jsアプリの作成] adash33317.nuxt.jsのvuexでパスワード制限:index.html [2019/02/08] (現在) – [ソースコード] adash333
行 27: 行 27:
  
 ソースコード ソースコード
 +https://github.com/adash333/Nuxt-Vuex-FireAuth
  
- +スクリーンショット 
- +{{:17.nuxt.jsのvuexでパスワード制限:pasted:20190208-104526.png}} 
-Demo +{{:17.nuxt.jsのvuexでパスワード制限:pasted:20190208-104605.png}} 
 +{{:17.nuxt.jsのvuexでパスワード制限:pasted:20190208-104403.png}}
  
 ===== 開発環境 ===== ===== 開発環境 =====
行 63: 行 64:
 vuex-persistedstate@2.5.4 vuex-persistedstate@2.5.4
 </code> </code>
 +
 +起動するときは、<wrap hi>yarn run dev</wrap>
  
 ==== UbuntuのBashを利用するときの注意点 ==== ==== UbuntuのBashを利用するときの注意点 ====
行 333: 行 336:
  
 ~/pages/account.vue を新規作成します。 ~/pages/account.vue を新規作成します。
-<code+<html
-<template+<script src="https://gist.github.com/adash333/567c69d2faa04ddf4917c2542ee7ae15.js"></script
-  <div>+</html>
  
-    <!-- ログイン中に表示される画面 --> +{{:17.nuxt.jsのvuexでパスワード制限:pasted:20190208-100425.png}}
-    <div v-if="isAuthenticated"> +
-      <v-flex xs12 sm8 md4> +
-        <v-card class="elevation-12"> +
-          <v-toolbar dark color="primary"> +
-            <v-toolbar-title>ログイン中</v-toolbar-title> +
-            <v-spacer></v-spacer> +
-          </v-toolbar> +
-          <v-card-text> +
-            {{ user.email }}でログイン中です<br> +
-            <a href="/member-page">メンバーページへ</a> +
-          </v-card-text> +
-          <v-card-actions> +
-            <v-spacer></v-spacer> +
-            <v-btn color="primary" @click="logout">ログアウト</v-btn> +
-          </v-card-actions> +
-        </v-card> +
-      </v-flex> +
-    </div> +
- +
-    <!-- ログインしていない時に表示される画面 --> +
-    <div v-else> +
-      <v-flex xs12 sm8 md4> +
-        <v-card class="elevation-12"> +
-          <v-toolbar dark color="primary"> +
-            <v-toolbar-title>Login form</v-toolbar-title> +
-            <v-spacer></v-spacer> +
-          </v-toolbar> +
-          <v-card-text> +
-            <v-form> +
-              <v-text-field +
-                prepend-icon="mail" +
-                name="email" +
-                label="Email" +
-                type="text" +
-                v-model="email" +
-              ></v-text-field> +
-              <v-text-field +
-                id="password" +
-                prepend-icon="lock" +
-                name="password" +
-                label="Password" +
-                type="password" +
-                v-model="password" +
-              ></v-text-field> +
-            </v-form> +
-          </v-card-text> +
- +
-          <v-card-actions> +
-            <v-spacer></v-spacer> +
-            <v-btn color="primary" @click="login">ログイン</v-btn> +
-          </v-card-actions> +
-        </v-card> +
-      </v-flex> +
-    </div> +
- +
-    <!-- ログイン中に表示される画面 --> +
-    <div v-if="isAuthenticated"> +
-      {{ user.email }}でログイン中です<br> +
-      <button v-on:click="logout">ログアウト</button><br> +
-      <a href="/member-page">メンバーページへ</a> +
-    </div> +
- +
-  </div> +
-</template> +
- +
-<script> +
-import firebase from '~/plugins/firebase' +
-import { mapActions, mapState, mapGetters } from 'vuex' +
-export default { +
-  data() { +
-    return { +
-      email: '', +
-      password: '' +
-    } +
-  }, +
-  computed: { +
-    ...mapState(['user']), +
-    ...mapGetters(['isAuthenticated']) +
-  }, +
-  mounted() { +
-    firebase.auth().onAuthStateChanged((user) => { +
-      this.setUser(user) +
-    }) +
-  }, +
-  methods : { +
-    ...mapActions(['setUser']), +
-    login() { +
-      firebase.auth().signInWithEmailAndPassword(this.email, this.password) +
-      .then(user => { +
-        // ログインしたら飛ぶページを指定 +
-        // this.$router.push("/member-page"+
-      }).catch((error) => { +
-        alert(error) +
-      }); +
-    }, +
-    logout() { +
-      firebase.auth().signOut() +
-      .then(() => { +
-        this.setUser(null) +
-      }).catch((error) => { +
-        alert(error) +
-      }) +
-    } +
-  } +
-+
-</script> +
-</code> +
-{{:17.nuxt.jsのvuexでパスワード制限:pasted:20190207-150707.png}}+
  
 ===== Firebaseでメールアドレス/パスワードのアカウントを作成 ===== ===== Firebaseでメールアドレス/パスワードのアカウントを作成 =====
行 500: 行 395:
 slotというものを初めて見ましたが、なんかややこしく感じます。 slotというものを初めて見ましたが、なんかややこしく感じます。
  
 +===== pages/member-page.vueの作成 =====
  
 +pages/member-page.vueを新規作成します。
 +<code>
 +<template>
 +  <v-flex xs12 sm6 offset-sm3>
 +    <v-card class="elevation-12">
 +      <members-only>
 +        <v-toolbar dark color="primary">
 +          <v-toolbar-title>ログインしていないと見れないページ</v-toolbar-title>
 +            <v-spacer></v-spacer>
 +          </v-toolbar>
 +          <v-card-text>
 +           ログイン中です<br>
 +            <a href="/account">アカウントページへ</a>
 +          </v-card-text>
 +      </members-only>
 +    </v-card>
 +  </v-flex>
 +</template>
  
 +<script>
 +import MembersOnly from '~/components/members-only.vue'
  
 +export default {
 +  components: {
 +    MembersOnly
 +  }
 +}
 +</script>
 +</code>
  
 +{{:17.nuxt.jsのvuexでパスワード制限:pasted:20190208-103951.png}}
  
 +ログインしていない状態だと、member-pageから、accountに自動的に飛びます。
 +
 +今回は以上となります。
  
  
行 523: 行 450:
  
  
-===== Nuxt.jsのvuex(モジュールモード)でパスワード制限 ===== 
  
  
行 529: 行 455:
 ===== ソースコード ===== ===== ソースコード =====
 ソースコード ソースコード
 +https://github.com/adash333/Nuxt-Vuex-FireAuth
  
 DEMO DEMO
 +{{:17.nuxt.jsのvuexでパスワード制限:pasted:20190208-104651.png}}
  
 ===== 今回写経させて頂いたサイト ===== ===== 今回写経させて頂いたサイト =====


17.nuxt.jsのvuexでパスワード制限/index.html.1549617695.txt.gz · 最終更新: 2019/02/08 by adash333

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki