Advertisement
Guest User

Untitled

a guest
Mar 13th, 2017
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import * as firebase from 'firebase'
  4.  
  5. Vue.use(Vuex);
  6.  
  7. export const store = new Vue.Store({
  8. state: {
  9. loggedIn: false,
  10. userName: 'Guest',
  11. errorMessage: ''
  12. },
  13. getters: {
  14.  
  15. },
  16. mutations: {
  17. m_logInUser: (state) => {
  18. state.loggedIn = true;
  19. }
  20. },
  21. actions: {
  22. a_logInUser: ({state, dispatch}, user) => {
  23. firebase.auth().signInWithEmailAndPassword(user.e, user.p).catch(function(error) {
  24. // Handle Errors here.
  25. state.errorMessage = error.message;
  26. });
  27. dispatch('a_authStateObserver');
  28. },
  29. a_authStateObserver: ({commit, state}) => {
  30. firebase.auth().onAuthStateChanged(function(user) {
  31. if (user) {
  32. // User is signed in.
  33. var displayName = user.displayName;
  34. state.userName = user.email;
  35. commit('m_logInUser');
  36. alert("you logged in");
  37. } else {
  38. // User is signed out.
  39. // ...
  40. }
  41. });
  42. }
  43. }
  44. });
  45.  
  46. <template>
  47. <div class="container">
  48. <div class="row">
  49. <div class="form_bg center-block">
  50. <form @submit.prevent="a_logInUser({e: email, p: password})">
  51. <h3 class="text-center">Log in</h3>
  52. <br/>
  53. <div class="form-group">
  54. <input v-model="email" type="email" class="form-control" placeholder="Your Email">
  55. </div>
  56. <div class="form-group">
  57. <input v-model="password" type="password" class="form-control" placeholder="Password">
  58. </div>
  59. <div class="align-center">
  60. <button type="submit" class="btn btn-success center-block">Log in</button>
  61. </div>
  62. </form>
  63. <br>
  64. <p style="display:inline-block">Don't have an account?</p>
  65. <router-link to="/signup" tag="a" style="display:inline-block">Sign up</router-link>
  66. </div>
  67. </div>
  68.  
  69. <script>
  70. import { mapActions } from 'vuex'
  71. export default{
  72. data(){
  73. return{
  74. email: '',
  75. password: ''
  76. };
  77. },
  78. methods: {
  79. ...mapActions([
  80. 'a_logInUser'
  81. ])
  82. }
  83. }
  84. </script>
  85.  
  86. Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_0_vue___default.a.Store is not a constructor
  87. at eval (eval at <anonymous> (build.js:1123), <anonymous>:13:13)
  88. at Object.<anonymous> (build.js:1123)
  89. at __webpack_require__ (build.js:660)
  90. at fn (build.js:84)
  91. at eval (eval at <anonymous> (build.js:1051), <anonymous>:12:71)
  92. at Object.<anonymous> (build.js:1051)
  93. at __webpack_require__ (build.js:660)
  94. at fn (build.js:84)
  95. at Object.<anonymous> (build.js:1632)
  96. at __webpack_require__ (build.js:660)
  97. http://localhost:8080/favicon.ico Failed to load resource: the server responded with a status of 404 (Not Found)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement