From 4afe9795dd67d6f0c3aa191d759e5a6f2b6b58e3 Mon Sep 17 00:00:00 2001 From: gabang2 Date: Sat, 1 Jun 2024 14:43:55 +0900 Subject: [PATCH] =?UTF-8?q?=EC=B6=94=EA=B0=80:=20firebase=20key=20again?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/global/config/FirebaseConfig.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/project/backend/global/config/FirebaseConfig.java b/src/main/java/project/backend/global/config/FirebaseConfig.java index ebc13ff..7403aa3 100644 --- a/src/main/java/project/backend/global/config/FirebaseConfig.java +++ b/src/main/java/project/backend/global/config/FirebaseConfig.java @@ -3,20 +3,25 @@ import com.google.auth.oauth2.GoogleCredentials; import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseOptions; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.io.ClassPathResource; +import java.io.ByteArrayInputStream; import java.io.IOException; -import java.io.InputStream; @Configuration public class FirebaseConfig { @Bean public FirebaseApp initializeFirebaseApp() throws IOException { - ClassPathResource resource = new ClassPathResource("firebase-service-key.json"); - InputStream serviceAccount = resource.getInputStream(); + String firebaseConfig = System.getenv("FCM_SECRET"); + if (firebaseConfig == null) { + throw new IOException("FCM_SECRET environment variable is not set."); + } + + ByteArrayInputStream serviceAccount = new ByteArrayInputStream(firebaseConfig.getBytes()); FirebaseOptions options = new FirebaseOptions.Builder() .setCredentials(GoogleCredentials.fromStream(serviceAccount))