Created
July 19, 2025 17:14
-
-
Save williamjayjay/b459e221a07f939d0b9b2a2059091217 to your computer and use it in GitHub Desktop.
Cloud Function to return .env
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { onCall, CallableRequest, HttpsError } from "firebase-functions/v2/https"; | |
import * as logger from "firebase-functions/logger"; | |
import * as admin from "firebase-admin"; | |
admin.initializeApp(); | |
export const getMetalcodeAccessToken = onCall(async (request: CallableRequest<unknown>) => { | |
// Acesse o token via process.env | |
const accessToken = process.env.METALCODEAPI_ACCESS_TOKEN; | |
if (!accessToken) { | |
logger.error("Token de acesso da API do Metalcode não configurado via variáveis de ambiente."); | |
throw new HttpsError( | |
"internal", | |
"Erro de configuração do servidor: Token de acesso da API do Metalcode está faltando." | |
); | |
} | |
logger.info("Token da API do Metalcode recuperado com sucesso.", { | |
accessTokenPresent: !!accessToken, | |
}); | |
return { token: accessToken }; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment