我最近允许用户使用谷歌0Auth2登录我的expo 应用程序.0
问题是,当我需要验证后端提供的令牌时,我有一个400错误.
(仅使用谷歌提供的令牌,不使用我从基本邮箱/密码身份验证中获得的令牌)
- 在我的客户中:
export async function getUser(id){
console.log("Reading user... ")
try{
const token = await auth.currentUser.getIdToken()
const response = await axios.get(`${root}/users/get_currentuser/${id}?auth=${token}`)
return response.data
}
catch(err){
console.log(err.message)
}
}
- 在我的后台:
const get_currentuser = async (req, res) => {
const id = req.params.id
const auth = req.query.auth
try {
const result = await getAuth().verifyIdToken(auth) // the error is here
if(result.uid === id){
try {
const user = await db.collection("Users").findOne({uid : id})
res.status(200).json(user)
} catch (error) {
res.status(500).json(error)
}
}
else
res.status(400).json({err : "Connexion impossible"})
} catch (error) {
res.status(400).json({err : "Connexion impossible / token error "})
}
}
提前感谢您的帮助!