cannot use getidtoken if null

JavaScript
// get the current user inside the observer
// then refresh the token
// and finally unsubscribe the observer
const getIdTokenRefreshed = async () => {
  return new Promise(async (resolve, reject) => {
     const unsubscribe = firebase
     	.auth
     	.onAuthStateChanged(user => {
          unsubscribe()
          const refreshedToken = await user
              .getIdToken(true)
              .catch(err => console.error(err))
          resolve(refreshedToken)
     }, reject)
  });
}
Source

Also in JavaScript: