Skip to content

Commit d595078

Browse files
committed
FIX: Authが正しく行えない問題
1 parent f17ba5f commit d595078

File tree

9 files changed

+34
-97
lines changed

9 files changed

+34
-97
lines changed

firebase.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
{
2-
"firestore": {
3-
"rules": "firestore.rules",
4-
"indexes": "firestore.indexes.json"
5-
},
62
"functions": {
73
"source": "dist/server",
84
"predeploy": [
@@ -23,9 +19,6 @@
2319
}
2420
]
2521
},
26-
"storage": {
27-
"rules": "storage.rules"
28-
},
2922
"emulators": {
3023
"functions": {
3124
"port": 5001

firestore.indexes.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

firestore.rules

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/pages/account/login.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,22 @@ export default {
5858
},
5959
methods: {
6060
...mapActions('modules/user', ['login']),
61-
async doLogin() {
62-
await firebase
61+
doLogin() {
62+
firebase
6363
.auth()
6464
.signInWithEmailAndPassword(this.email, this.password)
65-
.then((user) => {
66-
this.login(user)
65+
.then((userInfo) => {
66+
this.login(userInfo)
67+
})
68+
.then(() => {
6769
this.$router.push('/edit')
6870
})
6971
.catch((error) => {
7072
alert(error)
7173
})
7274
},
7375
gotoSignup() {
74-
this.$router.push('/signup')
76+
this.$router.push('/account/signup')
7577
},
7678
gotoResetPassword() {
7779
this.$router.push('/reset-password')

src/pages/account/signup.vue

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<v-card-actions>
3232
<v-btn @click="gotoSignin">Login</v-btn>
3333
<v-spacer />
34-
<v-btn @click="doSignin">Signin</v-btn>
34+
<v-btn @click="doSignup">Signup</v-btn>
3535
</v-card-actions>
3636
<hr />
3737
<v-spacer />
@@ -58,32 +58,34 @@ export default {
5858
},
5959
methods: {
6060
...mapActions('modules/user', ['login']),
61-
async doLogin() {
62-
await firebase
61+
doSignup() {
62+
firebase
6363
.auth()
6464
.createUserWithEmailAndPassword(this.email, this.password)
65-
.then((user) => {
65+
.then((userInfo) => {
6666
this.login({
67-
uid: user.uid,
68-
email: user.email,
69-
username: user.displayName,
70-
userImage: user.photoURL,
67+
uid: userInfo.user.uid,
68+
email: userInfo.user.email,
69+
username: userInfo.user.displayName,
70+
userImage: userInfo.user.photoURL,
7171
})
72-
this.writeUserData(user.uid, user.email)
72+
this.writeUserData(userInfo.user.uid, userInfo.user.email)
73+
})
74+
.then(() => {
7375
this.$router.push('/edit')
7476
})
7577
.catch((error) => {
7678
alert(error)
7779
})
7880
},
7981
gotoSignin() {
80-
this.$router.push('/signin')
82+
this.$router.push('/account/signin')
8183
},
8284
gotoResetPassword() {
8385
this.$router.push('/reset-password')
8486
},
8587
writeUserData(userId, email) {
86-
return firebase.firestore().collection('classData').doc(userId).set({
88+
return firebase.firestore().collection('users').doc(userId).set({
8789
email,
8890
})
8991
},

src/pages/edit/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<h1>{{ uid }}</h1>
2+
<h1>{{ userData }}</h1>
33
</template>
44

55
<script>
@@ -9,7 +9,7 @@ export default {
99
layout: 'protected',
1010
name: 'IndexVue',
1111
computed: {
12-
...mapGetters('modules/user', ['uid']),
12+
...mapGetters('modules/user', ['userData']),
1313
},
1414
}
1515
</script>

src/store/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const actions = {
1111
const classData = classDataSnapshot.data()
1212
await dispatch('modules/class/setClassData', { classData })
1313
if (user) {
14-
await dispatch('modules/user/setUser', {
14+
await dispatch('modules/user/setUserData', {
1515
name: user.name,
1616
email: user.email,
1717
avatar: user.picture,

src/store/modules/user.js

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,80 +2,48 @@ import Cookies from 'js-cookie'
22
import firebase from '@/plugins/firebase.js'
33

44
export const state = () => ({
5-
user: null,
6-
info: null,
7-
uid: null,
5+
userData: null,
86
})
97

108
export const mutations = {
11-
setUser(state, payload) {
9+
setUserData(state, payload) {
1210
if (payload) {
13-
state.user = payload
11+
state.userData = payload
1412
} else {
15-
state.user = null
16-
}
17-
},
18-
saveUid(state, payload) {
19-
if (payload) {
20-
state.uid = payload
21-
} else {
22-
state.uid = null
23-
}
24-
},
25-
setInfo(state, payload) {
26-
if (payload) {
27-
state.info = payload
28-
} else {
29-
state.info = null
13+
state.userData = null
3014
}
3115
},
3216
}
3317

3418
export const actions = {
3519
async login({ dispatch, state }, user) {
36-
console.log('userlogin')
3720
const token = await firebase.auth().currentUser.getIdToken(true)
3821
const userInfo = {
3922
name: user.displayName,
4023
email: user.email,
4124
avatar: user.photoURL,
4225
uid: user.uid,
4326
}
44-
4527
Cookies.set('access_token', token) // saving token in cookie for server rendering
46-
await dispatch('setUser', userInfo)
47-
await dispatch('saveUid', userInfo.uid)
28+
await dispatch('setUserData', userInfo)
4829
},
4930

5031
async logout({ commit }) {
5132
await firebase.auth().signOut()
5233

5334
Cookies.remove('access_token')
54-
commit('setUser', null)
55-
commit('saveUid', null)
56-
},
57-
setUser({ commit }, payload) {
58-
commit('setUser', payload)
35+
commit('setUserData', null)
5936
},
60-
saveUid({ commit }, payload) {
61-
commit('saveUid', payload)
62-
},
63-
setInfo({ commit }, payload) {
64-
commit('setInfo', payload)
37+
setUserData({ commit }, payload) {
38+
commit('setUserData', payload)
6539
},
6640
}
6741

6842
export const getters = {
69-
user: (state) => {
70-
return state.user
71-
},
72-
info: (state) => {
73-
return state.info
74-
},
75-
uid: (state) => {
76-
return state.uid
43+
userData: (state) => {
44+
return state.userData
7745
},
7846
isAuthenticated: (state) => {
79-
return !!state.user && !!state.user.uid
47+
return !!state.userData && !!state.userData.uid
8048
},
8149
}

storage.rules

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)