Skip to content

Commit 5a41754

Browse files
authored
fix: guard against an empty token store in fcm output (#279)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent a6d5a62 commit 5a41754

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

output/push/fcm_repository.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ func storeFCMToken(c *gin.Context) {
7777
}
7878

7979
store := getTokenStore()
80+
if store == nil {
81+
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed getting token store"})
82+
return
83+
}
8084
store.FCMTokens[req.FCMToken] = req.FCMToken
8185
c.Status(http.StatusCreated)
8286
}
@@ -92,6 +96,10 @@ func storeFCMToken(c *gin.Context) {
9296
func readFCMToken(c *gin.Context) {
9397
token := c.Param("token")
9498
store := getTokenStore()
99+
if store == nil {
100+
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed getting token store"})
101+
return
102+
}
95103
storedToken, exists := store.FCMTokens[token]
96104
if !exists {
97105
c.Status(http.StatusNotFound)
@@ -111,6 +119,10 @@ func readFCMToken(c *gin.Context) {
111119
func deleteFCMToken(c *gin.Context) {
112120
token := c.Param("token")
113121
store := getTokenStore()
122+
if store == nil {
123+
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed getting token store"})
124+
return
125+
}
114126
_, exists := store.FCMTokens[token]
115127
if exists {
116128
delete(store.FCMTokens, token)
@@ -123,5 +135,8 @@ func deleteFCMToken(c *gin.Context) {
123135
// GetFcmTokens returns the current in-memory FCM tokens
124136
func GetFcmTokens() map[string]string {
125137
store := getTokenStore()
138+
if store == nil {
139+
return make(map[string]string)
140+
}
126141
return store.FCMTokens
127142
}

0 commit comments

Comments
 (0)