admin管理员组文章数量:1202959
I am dealing with firebase auth now and I was following this Firebase document.
Visit
// When the user signs in with email and password.
firebase.auth().signInWithEmailAndPassword('[email protected]', '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);
});
})
I expected that I could get a token by using that function. But It doesn't work because user in the code doesn't have getIdToken() function.
I am dealing with firebase auth now and I was following this Firebase document.
Visit https://firebase.google.com/docs/auth/admin/manage-cookies#sign_in
// When the user signs in with email and password.
firebase.auth().signInWithEmailAndPassword('[email protected]', '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);
});
})
I expected that I could get a token by using that function. But It doesn't work because user in the code doesn't have getIdToken() function.
Share Improve this question asked Aug 18, 2019 at 9:19 Seungsik ShinSeungsik Shin 2051 gold badge3 silver badges6 bronze badges 4- Maybe it is because of space in arrow function = > – Lazar Nikolic Commented Aug 18, 2019 at 9:21
- what's the firebase/auth package version you are using? – Federkun Commented Aug 18, 2019 at 9:31
- @Federkun It is 7.22 – Seungsik Shin Commented Aug 18, 2019 at 11:25
- @LazarNikolic I fixed that part, but I got same error still.. – Seungsik Shin Commented Aug 18, 2019 at 11:25
2 Answers
Reset to default 11Seems like things changed since 7.* version. To get it:
firebase.auth().signInWithEmailAndPassword('[email protected]', '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);
});
})
Note, that you need to use user.user.getIdToken()
now, or just use destructuring as I did in the example.
To get the id token, just call auth's currentUser#getIdToken
directly.
const idToken = await firebase.auth().currentUser.getIdToken()
本文标签:
版权声明:本文标题:javascript - getIdToken() is not a function, even if It is used like a function in firebase document - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738662550a2105509.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论