Skip to content

Commit

Permalink
Fix double device registration
Browse files Browse the repository at this point in the history
In case the same device is registered with a new user it can lead to
receiving push notifications not targeted at the user. To alleviate this
we check if their is a device with the same token regardless which user
it belongs to.
  • Loading branch information
Alexander Simmerl committed Dec 9, 2016
1 parent 461a468 commit c7a6853
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions core/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func DeviceUpdate(devices device.Service) DeviceUpdateFunc {
token string,
language string,
) error {
// Get user devices.
ds, err := devices.Query(currentApp.Namespace(), device.QueryOptions{
Deleted: &defaultDeleted,
Platforms: []sns.Platform{
Expand All @@ -211,6 +212,19 @@ func DeviceUpdate(devices device.Service) DeviceUpdateFunc {
return err
}

// Check if there is a device with that token.
ts, err := devices.Query(currentApp.Namespace(), device.QueryOptions{
Deleted: &defaultDeleted,
Tokens: []string{
token,
},
})
if err != nil {
return nil, err
}

ds = append(ds, ts...)

d := &device.Device{}

for _, dev := range ds {
Expand Down

0 comments on commit c7a6853

Please sign in to comment.