admin管理员组文章数量:1302275
I am building a React Native app which uses Firebase phone authentication for user login. Authentication works fine but the token expires after an hour. I have read that I need to use the refresh token to refresh the idToken
, but nowhere on the Firebase docs does it explain how to do this. It only explains how to revoke refresh tokens, and I can't even find it.
I am using the react-native-firebase package.
My questions are: how to I get the refresh token, how do I use it, and do I really need to call Firebase every hour to update my idToken
?
I am currently getting my idToken
like this:
const authenticate = async (credential) => {
try {
const { user } = await firebase.auth().signInWithCredential(credential);
const accessToken = await user.getIdToken();
return accessToken;
} catch (error) {
console.log(error);
}
}
I then take the token and store it locally using AsyncStorage
and check if the token exists every time the app is launched.
Thanks in advance.
I am building a React Native app which uses Firebase phone authentication for user login. Authentication works fine but the token expires after an hour. I have read that I need to use the refresh token to refresh the idToken
, but nowhere on the Firebase docs does it explain how to do this. It only explains how to revoke refresh tokens, and I can't even find it.
I am using the react-native-firebase package.
My questions are: how to I get the refresh token, how do I use it, and do I really need to call Firebase every hour to update my idToken
?
I am currently getting my idToken
like this:
const authenticate = async (credential) => {
try {
const { user } = await firebase.auth().signInWithCredential(credential);
const accessToken = await user.getIdToken();
return accessToken;
} catch (error) {
console.log(error);
}
}
I then take the token and store it locally using AsyncStorage
and check if the token exists every time the app is launched.
Thanks in advance.
Share edited Aug 20, 2019 at 9:49 Mr. Robot asked Aug 20, 2019 at 9:41 Mr. RobotMr. Robot 1,8349 gold badges36 silver badges94 bronze badges1 Answer
Reset to default 8From https://rnfirebase.io/reference/auth/user#getIdToken
It seems that using user.getIdToken()
refresh the token if it has expired.
You can always use the forceRefresh
option if you want to refresh the token even if it's still valid.
本文标签: javascriptHow do I persist user authentication using the Firebase refresh tokenStack Overflow
版权声明:本文标题:javascript - How do I persist user authentication using the Firebase refresh token? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741712522a2393923.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论