How to retrieve a user firebase auth ID token in the new firebase version 9?

How to retrieve a user firebase auth ID token in the new firebase version 9?

This is how it is done in firebase version 8 below

firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idToken) { // Send token to your backend via HTTPS // ...}).catch(function(error) { // Handle error});

Does anyone know how it is done in firebase version 9?

found the answer


import { getAuth, getIdToken } from "firebase/auth"

const auth = getAuth();
const user = auth.currentUser

if (user) {
  getIdToken(user).then((token) => {
    console.log(token)
  })
}

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.