Skip to content

Commit

Permalink
fix: avoid using updated hook
Browse files Browse the repository at this point in the history
  • Loading branch information
jkklapp committed May 26, 2022
1 parent c48e523 commit c3f74b4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
1 change: 1 addition & 0 deletions frontend/src/components/Dashboard.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('Dashboard', () => {
uid: 1,
getIdToken: jest.fn().mockReturnValue(Promise.resolve('token')),
},
onAuthStateChanged: jest.fn(() => ({ email: 'test' })),
});
axios.get.mockResolvedValueOnce({ data: POSTS_RESPONSE_FIXTURE });
axios.post.mockResolvedValueOnce({ data: POSTS_RESPONSE_FIXTURE[0] });
Expand Down
12 changes: 8 additions & 4 deletions frontend/src/components/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<script>
import { mapGetters } from 'vuex';
import store from '../store';
import firebase from 'firebase/compat/app';
export default {
computed: {
Expand All @@ -37,10 +38,13 @@ export default {
},
},
},
updated() {
if (this.isLoggedIn) {
store.dispatch('fetchPosts');
}
mounted() {
firebase.auth().onAuthStateChanged((user) => {
if (user) {
store.dispatch('fetchUser', user);
store.dispatch('fetchPosts');
}
});
},
methods: {
submitMessage() {
Expand Down
6 changes: 0 additions & 6 deletions frontend/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ const firebaseConfig = {

firebase.initializeApp(firebaseConfig);

firebase.auth().onAuthStateChanged((user) => {
if (user) {
store.dispatch('fetchUser', user);
}
});

const app = createApp(App);
app.use(store);
app.use(router);
Expand Down

0 comments on commit c3f74b4

Please sign in to comment.