Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

576
Vistas
How to get a FireBase idToken on the server

According to the documentation, to verify the user role, you need to check the idToken of the current user. But where to get it? I just found the receipt on the client

I tried to do this:

app.get("/admin-cp", function (req, res) {
    const sessionCookie = req.cookies.session || "";
    
    admin
        .auth()
        .verifySessionCookie(sessionCookie, true  )
        .then((userData) => {
            console.log("Logged in:", userData.email)
            console.log('Авторизован. Доступ в админ панель открыт')

            const customToken = admin.auth().createCustomToken(userData.uid)
            admin
            .auth()
            .verifyIdToken(customToken)
            .then((claims) => 
            {  
                if (claims.admin === true) 
                {    
                    // Allow access to admin resource.   
                } 
            });

            res.sendFile(path.join(initial_path, "admin-cp/main-admin_cp.html"));
        })
        .catch((error) => {
            console.log('Не авторизован. Ошибка', error, ' отсутвует userData')
            res.redirect("/login");
        });
});
code: 'auth/argument-error',
message: 'First argument to verifyIdToken() must be a Firebase ID token string.'
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You should ideally pass the ID Token in your API request's headers from client side.

const idToken = await firebase.auth().currentUser.getIdToken()

const res = await fetch('/api-url', { headers: { authorization: idToken } })

Then you can read the token on server side:

const idToken = req.headers.authorization;

if (!idToken) return res.status(401).send("Unauthorized")

// verify token using verifySessionCookie() here 
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda