Skip to content

Commit cf0e6cc

Browse files
committed
ADD: ClassData Access Control
1 parent 68b527f commit cf0e6cc

File tree

3 files changed

+24
-27
lines changed

3 files changed

+24
-27
lines changed

src/pages/classes/index.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { mapGetters } from 'vuex'
2323
import StudyCard from '@/components/StudyCard'
2424
export default {
2525
components: { StudyCard },
26+
middleware: 'checkClassData',
2627
computed: {
2728
...mapGetters('modules/class', ['Lessons']),
2829
},

src/pages/index.vue

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<div class="Logo">
55
<Logo style="height: 80vw; max-height: 350px; width: 100%;" />
66
</div>
7+
{{ errorMessages }}
78
<div class="LoginForm">
89
<v-form ref="form" v-model="valid">
910
<v-text-field
@@ -45,7 +46,6 @@ export default {
4546
error: false,
4647
errorMessages: '',
4748
valid: true,
48-
exists: false,
4949
nameRules: [
5050
(v) => !!v || 'クラスIDは必須です',
5151
(v) => (v && v.length === 6) || 'クラスIDは6文字のひらがなです',
@@ -56,32 +56,24 @@ export default {
5656
...mapActions('modules/class', ['loadClassData']),
5757
checkInClass() {
5858
this.loading = true
59-
this.checkExistsClassData(this.classId)
60-
if (this.exists) {
61-
this.loadClassData(this.classId)
62-
this.$router.push('classes')
63-
} else {
64-
this.loading = false
65-
this.error = true
66-
this.errorMessages = 'クラスIDが間違っています'
67-
}
59+
this.checkExistsClassData(this.classId).then((value) => {
60+
if (value) {
61+
this.loadClassData(this.classId)
62+
this.$router.push('/classes')
63+
} else {
64+
this.loading = false
65+
this.error = true
66+
this.errorMessages = 'クラスIDが間違っています'
67+
}
68+
})
6869
},
69-
checkExistsClassData(classid) {
70-
if (classid !== '' || classid !== null || classid !== '') {
71-
firebase
72-
.firestore()
73-
.collection('classData')
74-
.doc(classid)
75-
.get()
76-
.then(() => {
77-
this.exists = true
78-
})
79-
.catch(() => {
80-
this.exists = false
81-
})
82-
} else {
83-
this.exists = false
84-
}
70+
async checkExistsClassData(classid) {
71+
const check = await firebase
72+
.firestore()
73+
.collection('classData')
74+
.doc(classid)
75+
.get()
76+
return check.exists
8577
},
8678
},
8779
}

src/store/modules/class.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export const getters = {
2020
Lessons(state) {
2121
return state.classData.Lessons
2222
},
23+
isLoadedClassData: (state) => {
24+
return state.classId !== ''
25+
},
2326
}
2427

2528
export const mutations = {
@@ -41,6 +44,7 @@ export const actions = {
4144
const classDa = await classDataSnapshot.data()
4245
await dispatch('setClassData', classDa)
4346
await dispatch('setClassId', classId)
47+
await dispatch('isLoadedClassData')
4448
},
4549
setClassData({ commit }, classData) {
4650
commit('setClassData', classData)
@@ -49,6 +53,6 @@ export const actions = {
4953
commit('setClassId', classId)
5054
},
5155
isLoadedClassData: (state) => {
52-
return !!state.classData
56+
return state.classData !== {}
5357
},
5458
}

0 commit comments

Comments
 (0)