Reputation: 895
I'm using Firebase in my Flutter app. So i need make Refresh Token automatically, without user Know.
I'm using provider in my Flutter for using Screen management. The if user!= null
goes to the Home, if user==null
go to the Login Screen.
When I make Search for Solution I read in Firebase auth that the uuid Token expires after an Hour.
So i need Refresh Token Before expired How to make this?
Widget build(BuildContext context) {
// TODO: implement build
final user =Provider.of<User>(context);
print(user);
getToken();
if (user!=null){
print('token $token');
return Home();
}else{
return login();
}
}
this is regsiter function
Future regsiterwithemail(String email , String password )
async {
try{
AuthResult result =await _auth.createUserWithEmailAndPassword(email: email, password: password);
FirebaseUser user =result.user;
await DataBaseService(uid: user.uid,email: user.email,TitleNews:"").CreateDocumentInDataBase();
return _userFromFirebaseUser(user);
}catch(e){
print(e.toString());
return null;
}
}
this login Function
Future SigniWithEmail(String email ,String password)async {
try{
AuthResult result=await _auth.signInWithEmailAndPassword(email: email, password:password);
FirebaseUser user= result.user;
return _userFromFirebaseUser(user);
}
catch(e){
print(e.toString());
return null;
}
}
Upvotes: 1
Views: 671
Reputation: 598807
Firebase automatically refreshes the (short-lived) ID token behind the scenes. You don't need to do anything for this to happen.
The user's UID won't change when the ID token changes. In fact, the ID token of a user will remain the same for as long as their account exists.
Upvotes: 2