Skip to content

Commit

Permalink
추가: firebase key again
Browse files Browse the repository at this point in the history
  • Loading branch information
rrosiee committed Jun 1, 2024
1 parent 78c5fae commit 4afe979
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/java/project/backend/global/config/FirebaseConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 4afe979

Please sign in to comment.