gpt4 book ai didi

javascript - getIdToken() 不是函数,即使它在 firebase 文档中像函数一样使用

转载 作者:行者123 更新时间:2023-11-30 19:20:19 29 4
gpt4 key购买 nike

我现在正在处理 firebase 身份验证,我正在关注这个 Firebase 文档。

访问https://firebase.google.com/docs/auth/admin/manage-cookies#sign_in

// When the user signs in with email and password.
firebase.auth().signInWithEmailAndPassword('user@example.com', 'password').then(user => {
// Get the user's ID token as it is needed to exchange for a session cookie.
return user.getIdToken().then(idToken = > {
// Session login endpoint is queried and the session cookie is set.
// CSRF protection should be taken into account.
// ...
const csrfToken = getCookie('csrfToken')
return postIdTokenToSessionLogin('/sessionLogin', idToken, csrfToken);
});
})

我希望我可以通过使用该功能获得 token 。但是它不起作用,因为代码中的用户没有 getIdToken() 函数。

最佳答案

似乎自 7.* 版本以来发生了变化。获取方式:

firebase.auth().signInWithEmailAndPassword('user@example.com', 'password').then(({ user }) => {
// Get the user's ID token as it is needed to exchange for a session cookie.
return user.getIdToken().then(idToken = > {
// Session login endpoint is queried and the session cookie is set.
// CSRF protection should be taken into account.
// ...
const csrfToken = getCookie('csrfToken')
return postIdTokenToSessionLogin('/sessionLogin', idToken, csrfToken);
});
})

请注意,您现在需要使用 user.user.getIdToken(),或者像我在示例中那样使用解构。

关于javascript - getIdToken() 不是函数,即使它在 firebase 文档中像函数一样使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57543208/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com