1// get the current user inside the observer
2// then refresh the token
3// and finally unsubscribe the observer
4const getIdTokenRefreshed = async () => {
5 return new Promise(async (resolve, reject) => {
6 const unsubscribe = firebase
7 .auth
8 .onAuthStateChanged(user => {
9 unsubscribe()
10 const refreshedToken = await user
11 .getIdToken(true)
12 .catch(err => console.error(err))
13 resolve(refreshedToken)
14 }, reject)
15 });
16}