OneSignal / OneSignal-Flutter-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your flutter app with OneSignal
https://www.onesignal.com
Other
620 stars 212 forks source link

[Bug]: One or more Aliases claimed by another User #714

Open jt274 opened 1 year ago

jt274 commented 1 year ago

What happened?

v5.0.0 throws the error after following the migration guide and using an existing user. App uninstall/reinstall does not fix the issue. Issue did not occur on Android emulator using User1 account, but did occur on physical device using User2 account.

The docs specifically state that if the user already exists when logging in, the user will be updated. If the user does not exist, they will be created.

After throwing the error, it repeatedly retries in an infinite loop.

OneSignal.initialize('APP_ID');

await OneSignal.login('USER_ID');

await OneSignal.User.pushSubscription.optIn();

Additionally, the following error is thrown:

MissingPluginException(No implementation found for method OneSignal#optIn on channel OneSignal#pushsubscription)

Steps to reproduce?

1. Upgrade onesignal_flutter from 3.5.1 to 5.0.0 using the posted migration guide.
2. Run app as logged in user

What did you expect to happen?

User should be updated according to external_id. Any anonymous user should be merged with existing user according to external_id.

OneSignal Flutter SDK version

5.0.0

Which platform(s) are affected?

Relevant log output

D/OneSignal(22407): [OpRepo] IdentityOperationExecutor(operations: [{"name":"set-alias","appId":"APP_ID","onesignalId":"ONESIGNAL_ID","label":"external_id","value":"USER_ID"}])
D/OneSignal(22407): [DefaultDispatcher-worker-2] HttpClient: PATCH apps/APP_ID/users/by/onesignal_id/ONESIGNAL_ID/identity - {"identity":{"external_id":"USER_ID"}}
D/OneSignal(22407): [DefaultDispatcher-worker-10] HttpClient: PATCH apps/APP_ID/users/by/onesignal_id/ONESIGNAL_ID/identity - FAILED STATUS: 409
W/OneSignal(22407): [DefaultDispatcher-worker-10] HttpClient: PATCH RECEIVED JSON: {"errors":[{"code":"user-2","title":"One or more Aliases claimed by another User",
D/OneSignal(22407): [DefaultDispatcher-worker-10] HttpClient: POST apps/APP_ID/users - FAILED STATUS: 500
W/OneSignal(22407): [DefaultDispatcher-worker-10] HttpClient: POST RECEIVED JSON: 
D/OneSignal(22407): [OpRepo] OperationRepo: execute response = FAIL_RETRY

Code of Conduct

faccioliandrea commented 1 year ago

same issue

emawby commented 1 year ago

@jt274 Thank you for reporting we are investigating both issues. For the login issue how many devices have used the User1 external_id. There is a subscription limit of 20 subscriptions that you might be hitting when testing and the error message might misleading

jt274 commented 1 year ago

@emawby There has only been one (maybe two at most) device using that account. However it has run both debug and production versions of the app. So maybe it would cause an issue if the app is reinstalled more than once and it sees it as a new device each time?

emawby commented 1 year ago

@jt274 Yes a uninstall/reinstall counts as a new subscription (new push token) so that may be the issue, but the error message should indicate that subscription limit was hit in that case. It looks like the 409 is expected, but the SDK should be handling it for you. The 500 error in the log is likely the root cause of the problem. Are you able to share the request of the POST apps/APP_ID/users call that got the 500 error?

jt274 commented 1 year ago

@emawby So you are saying the SDK should handle it by, for example, deleting old subscriptions and properly updating the user?

Are you wanting the app ID and user's onesignal ID (the parts I redacted)?

jt274 commented 1 year ago

@emawby

If I search the external ID in the onesignal dashboard, it pulls up 6 subscriptions matching the external ID, all associated with one onesignal ID.

I believe this is the 500 error you're referring to:

[DefaultDispatcher-worker-3] HttpClient: POST apps/APP_ID/users - {"identity":{"external_id":"USER_ID"},"subscriptions":[{"id":"ONESIGNAL_ID","token":"PUSH_TOKEN","enabled":true,"notification_types":1},{"type":"Email","token":"me@email.com","enabled":true,"notification_types":1,"sdk":"050000","device_model":"SM-G981V","device_os":"12","rooted":false,"net_type":0,"carrier":"US  Mobile","app_version":"44"}]}
jt274 commented 1 year ago

@emawby

The app is trying to use the PATCH command to update the user alias using the onesignal_id alias label like so:

PATCH apps/APP_ID/users/by/onesignal_id/ONESIGNAL_USER_ID/identity

However, it returns the 409 error because the external id is already taken by another onesignal user. I believe it is supposed to update the already existing onesignal user by issuing the PATCH command using the external_id alias label like this instead:

PATCH apps/APP_ID/users/by/external_id/USER_ID/identity

This is according to the docs here: https://documentation.onesignal.com/reference/create-alias

The logged in user should then be linked to the onesignal_id associated with the provided external_id. Is that correct?

jt274 commented 1 year ago

Although I have not done extensive testing, this issue appears to be resolved on the back end. @emawby can you confirm?

RogerBrusamarello commented 11 months ago

any updates here?

ChoyCheeWei commented 10 months ago

any updates on this?

vasilich6107 commented 9 months ago

@emawby any updates?

nan-li commented 9 months ago

Hi @jt274 sorry for the delayed response.

There have been numerous backend fixes since August, so it may have been fixed. Are you still seeing this 500 response anymore?

I'll explain more about how the SDK handles the 409 response:

  1. When you call login to an existing user, this 409 response is expected. The reason is we are trying to attach that external_id to the local data in the SDK, since that user may be brand new. If the user is not new, this attempt to attach the external_id fails.
  2. We added a new log in recent releases to say the SDK is handling the response, for improved clarity.
  3. We clear the local state and fetch that existing user's data from the backend and populate the local data with that state.
nan-li commented 9 months ago

Hi @RogerBrusamarello @ChoyCheeWei @vasilich6107, please tell me more about what you are running into and what version of the SDK you are using.

gitananun commented 8 months ago

Having the same issue.

errors = ( { code = "user-2"; meta = { "external_id" = "..."; }; title = "One or more Aliases claimed by another User"; } ); httpStatusCode = 409;

Yurockkk commented 4 months ago

facing the same issue... any updates?

ArthurMiroslavsky commented 3 months ago

Same issue(( (v16)

HarunKilic commented 3 months ago

I do also have issue where same user signs in from another device. It throws the error. Tried to remove the subscriptions (all of them) and getting this error now: "One or more Aliases claimed by another User", even tho subscriptions are empty.

Marco2686 commented 3 months ago

Same here, tryed to delete the aliase with postman but get

{ "errors": [ { "title": "No subscription with alias(alias: my_alias)found" } ] }

KevinToala commented 1 month ago

Same error

lookmanrays commented 6 days ago

The same issue