diff --git a/nuxt-firebase-auth-master/pages/community/_communityId.vue b/nuxt-firebase-auth-master/pages/community/_communityId.vue index 913f982..3b4c6b7 100644 --- a/nuxt-firebase-auth-master/pages/community/_communityId.vue +++ b/nuxt-firebase-auth-master/pages/community/_communityId.vue @@ -122,14 +122,13 @@ -
- -
- - - -
- + />--> - -
-
- - - - photo_camera - - - assessment - - - event - - - - Post - - -
-
-
-
+ + + + + + + photo_camera + + + assessment + + + event + + + + Post + + + + + @@ -353,7 +351,6 @@ import Swal from "sweetalert2"; import axios from "axios"; import { mapGetters, mapActions } from "vuex"; - export default { name: "communityDetail", data() { @@ -435,7 +432,7 @@ export default { `${process.env.COMMUNITY_SERVICE}/community/${this.communityId}/subscribe/status`, { headers: { - "Authorization": `Bearer ${localStorage.getItem("jwtToken")}` + Authorization: `Bearer ${localStorage.getItem("jwtToken")}` } } ) @@ -449,28 +446,41 @@ export default { }, followCommunity() { let loader = this.$loading.show(); - axios - .post( - `${process.env.COMMUNITY_SERVICE}/community/${this.communityId}/subscribe`, - null, - { - headers: { - "Authorization": `Bearer ${localStorage.getItem("jwtToken")}` + if ( + localStorage.getItem("jwtToken") == null || + localStorage.getItem("jwtToken") === undefined + ) { + this.$swal({ + type: "error", + title: "Please login first !!!", + text: `Please login first !!!` + }); + this.$router.push("/login"); + loader.hide(); + } else { + axios + .post( + `${process.env.COMMUNITY_SERVICE}/community/${this.communityId}/subscribe`, + null, + { + headers: { + Authorization: `Bearer ${localStorage.getItem("jwtToken")}` + } } - } - ) - .then(joinCommunityResponse => { - this.isSubscribe = !this.isSubscribe; - loader.hide(); - }) - .catch(err => { - this.$swal({ - type: "error", - title: "Failed to subscribe community !!!", - text: `${err.response.data.response}` + ) + .then(joinCommunityResponse => { + this.isSubscribe = !this.isSubscribe; + loader.hide(); + }) + .catch(err => { + this.$swal({ + type: "error", + title: "Failed to subscribe community !!!", + text: `${err.response.data.response}` + }); + loader.hide(); }); - loader.hide(); - }); + } }, unfollowCommunity() { let loader = this.$loading.show(); @@ -480,7 +490,7 @@ export default { null, { headers: { - "Authorization": `Bearer ${localStorage.getItem("jwtToken")}` + Authorization: `Bearer ${localStorage.getItem("jwtToken")}` } } ) @@ -542,31 +552,43 @@ export default { postDetail: this.newPost, done: false }; - - axios - .post( - `${process.env.COMMUNITY_SERVICE}/community/${this.communityId}/post`, - postTemplate, - { - headers: { - Authorization: `Bearer ${localStorage.getItem("jwtToken")}` + if ( + localStorage.getItem("jwtToken") == null || + localStorage.getItem("jwtToken") === undefined + ) { + this.$swal({ + type: "error", + title: "Please login first !!!", + text: `Please login first !!!` + }); + this.$router.push("/login"); + loader.hide(); + } else { + axios + .post( + `${process.env.COMMUNITY_SERVICE}/community/${this.communityId}/post`, + postTemplate, + { + headers: { + Authorization: `Bearer ${localStorage.getItem("jwtToken")}` + } } - } - ) - .then(postResponse => { - this.postList.push(postTemplate); - this.newPost = ""; - console.log(this.postList); - loader.hide(); - }) - .catch(err => { - this.$swal({ - type: "error", - title: "Fail to post !!!", - text: `${err.response.data.response}` + ) + .then(postResponse => { + this.postList.push(postTemplate); + this.newPost = ""; + console.log(this.postList); + loader.hide(); + }) + .catch(err => { + this.$swal({ + type: "error", + title: "Fail to post !!!", + text: `${err.response.data.response}` + }); + loader.hide(); }); - loader.hide(); - }); + } }, // removePost(todo) { // const postIndex = this.postList.indexOf(todo);