Tom*_*Tom 7 javascript firebase vue.js firebase-authentication firebase-realtime-database
我正在使用Firebase实时数据库,我需要为其添加用户身份验证.用户只能使用Google作为提供商登录.
当前数据库模式:
{
"rules": {
".read": true,
".write": true
}
}
Run Code Online (Sandbox Code Playgroud)
新模式应该是这样的:
// These rules grant access to a node matching the authenticated
// user's ID from the Firebase auth token
{
"rules": {
"users": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在我的情况下,我应该使用什么来进行身份验证?userID,Google providerID或此处描述的令牌?
这是没有身份验证的功能来存储数据:
createMeetup ({commit, getters}, payload) {
console.log('index.js -> createMeetup')
const meetup = {
title: payload.title,
}
let imageUrl
let key
firebase.database().ref('meetups').push(meetup)
.then((data) => {
key = data.key
return key
})
.then(() => {
commit('createMeetup', {
...meetup,
imageUrl: imageUrl,
id: key
})
})
.catch((error) => {
console.log(error)
})
},
Run Code Online (Sandbox Code Playgroud)
您可以允许用户使用多种方法登录/身份验证。然后您可以将它们合并到一个帐户中,如下所述:
https://firebase.google.com/docs/auth/web/account-linking
所以实际上它可以归结为两个选择:
无论您选择哪个选项,都将帮助您决定使用哪个 ID。
| 归档时间: |
|
| 查看次数: |
842 次 |
| 最近记录: |