Skip to content

Commit

Permalink
fix: guard against an empty token store in fcm output (#279)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
  • Loading branch information
wolf31o2 authored Nov 14, 2024
1 parent a6d5a62 commit 5a41754
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions output/push/fcm_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func storeFCMToken(c *gin.Context) {
}

store := getTokenStore()
if store == nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed getting token store"})
return
}
store.FCMTokens[req.FCMToken] = req.FCMToken
c.Status(http.StatusCreated)
}
Expand All @@ -92,6 +96,10 @@ func storeFCMToken(c *gin.Context) {
func readFCMToken(c *gin.Context) {
token := c.Param("token")
store := getTokenStore()
if store == nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed getting token store"})
return
}
storedToken, exists := store.FCMTokens[token]
if !exists {
c.Status(http.StatusNotFound)
Expand All @@ -111,6 +119,10 @@ func readFCMToken(c *gin.Context) {
func deleteFCMToken(c *gin.Context) {
token := c.Param("token")
store := getTokenStore()
if store == nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "failed getting token store"})
return
}
_, exists := store.FCMTokens[token]
if exists {
delete(store.FCMTokens, token)
Expand All @@ -123,5 +135,8 @@ func deleteFCMToken(c *gin.Context) {
// GetFcmTokens returns the current in-memory FCM tokens
func GetFcmTokens() map[string]string {
store := getTokenStore()
if store == nil {
return make(map[string]string)
}
return store.FCMTokens
}

0 comments on commit 5a41754

Please sign in to comment.