OneSignal / OneSignal-Cordova-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Ionic, PhoneGap CLI, PhoneGap Build, Cordova, or Sencha Touch app with OneSignal. Supports Android, iOS, and Amazon's Fire OS platforms. https://onesignal.com
Other
251 stars 199 forks source link

[Bug]: Problem with upgrade from v3 to v5. Problem with post request #996

Closed websitevirtuoso closed 6 months ago

websitevirtuoso commented 6 months ago

What happened?

Problem with login request or initialize

Steps to reproduce?

1. Version - 5.1.4 my package.json file

{
  "description": "Teamo | Incentive focused, employee reward and engagement professionals",
  "license": "MIT",
  "dependencies": {
    "@capacitor/app": "^6.0.0",
    "@capacitor/android": "^6.0.0",
    "@capacitor/core": "^6.0.0",
    "@capacitor/ios": "^6.0.0",
    "@capacitor/splash-screen": "^6.0.0",
    "cordova-res": "^0.15.4",
    "onesignal-cordova-plugin": "^5.1.4"
  },
  "repository": {
    "type": "url",
    "url": "https://capacitorjs.com/"
  },
  "devDependencies": {
    "@capacitor/cli": "^6.0.0"
  }
}

### What did you expect to happen?

Have to work

### OneSignal Cordova SDK version

5.1.4

### Which platform(s) are affected?

- [ ] iOS
- [X] Android

### Relevant log output

```Shell
I am trying to upgrade from "onesignal-cordova-plugin": "3.3.1" to 5.1.4
Everything worked but right now I am getting error in my Android Studio

2024-05-21 14:53:10.341  1065-1065  LayerHistory            surfaceflinger                       I  com.ca.goteamo/com.ca.goteamo.MainActivity$_3895#6773 Max (can't resolve refresh rate)
2024-05-21 14:53:10.648  3895-4752  OneSignal               com.ca.goteamo                       D  [OpRepo] processQueueForever:ops:
                                                                                                    [bucket:0, retries:0, operation:{"name":"login-user","appId":"34c87996-464b-4e05-9ee9-c03b2e269aec","onesignalId":"local-84ee9d6f-0361-48fa-9a7f-4767c9e8112c","id":"e9bc67e3-b4db-460b-a55c-cac5a59bfa4f"}
                                                                                                    , bucket:0, retries:0, operation:{"name":"create-subscription","appId":"34c87996-464b-4e05-9ee9-c03b2e269aec","onesignalId":"local-84ee9d6f-0361-48fa-9a7f-4767c9e8112c","subscriptionId":"local-a0844f2f-90b1-4041-8dec-56b9a459c94b","type":"PUSH","enabled":false,"address":"","status":"NO_PERMISSION","id":"c40a7fed-f3a5-41a7-b08f-d787c3b25e47"}
                                                                                                    ]
2024-05-21 14:53:10.650  3895-4752  OneSignal               com.ca.goteamo                       D  [OpRepo] LoginUserOperationExecutor(operation: [{"name":"login-user","appId":"34c87996-464b-4e05-9ee9-c03b2e269aec","onesignalId":"local-84ee9d6f-0361-48fa-9a7f-4767c9e8112c","id":"e9bc67e3-b4db-460b-a55c-cac5a59bfa4f"}, {"name":"create-subscription","appId":"34c87996-464b-4e05-9ee9-c03b2e269aec","onesignalId":"local-84ee9d6f-0361-48fa-9a7f-4767c9e8112c","subscriptionId":"local-a0844f2f-90b1-4041-8dec-56b9a459c94b","type":"PUSH","enabled":false,"address":"","status":"NO_PERMISSION","id":"c40a7fed-f3a5-41a7-b08f-d787c3b25e47"}])
2024-05-21 14:53:10.685  3895-4746  OneSignal               com.ca.goteamo                       D  [DefaultDispatcher-worker-3] HttpClient: Request Sent = POST https://api.onesignal.com/apps/34c87996-464b-4e05-9ee9-c03b2e269aec/users - Body: {"subscriptions":[{"type":"AndroidPush","token":"","enabled":false,"notification_types":0,"sdk":"050113","device_model":"SM-X510","device_os":"14","rooted":false,"net_type":0,"app_version":"4"}],"properties":{"timezone_id":"America\/Vancouver","language":"en"},"refresh_device_metadata":true} - Headers: Accept=[application/vnd.onesignal.v1+json], Content-Type=[application/json; charset=UTF-8], OneSignal-Install-Id=[3a06d0de-b748-440d-b0f5-6b2d3c4de217], OneSignal-Subscription-Id=[local-a0844f2f-90b1-4041-8dec-56b9a459c94b], SDK-Version=[onesignal/android/050113], SDK-Wrapper=[onesignal/cordova/050104]
2024-05-21 14:53:10.696  3895-4746  CapacitorCookies        com.ca.goteamo                       I  Getting cookies at: 'https://api.onesignal.com/apps/34c87996-464b-4e05-9ee9-c03b2e269aec/users'
2024-05-21 14:53:10.895  3895-4746  OneSignal               com.ca.goteamo                       D  [DefaultDispatcher-worker-3] HttpClient: Got Response = POST https://api.onesignal.com/apps/34c87996-464b-4e05-9ee9-c03b2e269aec/users - FAILED STATUS: 401
2024-05-21 14:53:10.899  3895-4746  OneSignal               com.ca.goteamo                       W  [DefaultDispatcher-worker-3] HttpClient: Got Response = POST - STATUS: 401 - Body: {"errors":[{"code":"auth-1","title":"This operation requires 'Authorization' in the HTTP header"}]}
2024-05-21 14:53:10.902  3895-4752  OneSignal               com.ca.goteamo                       D  [OpRepo] OperationRepo: execute response = FAIL_UNAUTHORIZED
2024-05-21 14:53:10.905  3895-4752  OneSignal               com.ca.goteamo                       E  Operation execution failed without retry: [{"name":"login-user","appId":"34c87996-464b-4e05-9ee9-c03b2e269aec","onesignalId":"local-84ee9d6f-0361-48fa-9a7f-4767c9e8112c","id":"e9bc67e3-b4db-460b-a55c-cac5a59bfa4f"}, {"name":"create-subscription","appId":"34c87996-464b-4e05-9ee9-c03b2e269aec","onesignalId":"local-84ee9d6f-0361-48fa-9a7f-4767c9e8112c","subscriptionId":"local-a0844f2f-90b1-4041-8dec-56b9a459c94b","type":"PUSH","enabled":false,"address":"","status":"NO_PERMISSION","id":"c40a7fed-f3a5-41a7-b08f-d787c3b25e47"}]
2024-05-21 14:53:10.919  3895-4752  OneSignal               com.ca.goteamo                       D  [OpRepo] retryAfterSeconds: null
2024-05-21 14:53:11.120  3895-4752  OneSignal               com.ca.goteamo                       D  [OpRepo] processQueueForever:ops:
                                                                                                    null

Screenshot_20240521_151639

I have the js code in my app

        OneSignalInitLegacy(oneSignalKey, userID, userIDHash) {
            // Uncomment to set OneSignal device logging to VERBOSE
            // window.plugins.OneSignal.setLogLevel(6, 0);

            window.plugins.OneSignal.setAppId(oneSignalKey);
            window.plugins.OneSignal.removeExternalUserId();
            window.plugins.OneSignal.setExternalUserId(String(userID), userIDHash);
            window.plugins.OneSignal.promptForPushNotificationsWithUserResponse();
        },
        OneSignalInit(oneSignalKey, userID) {
            window.plugins.OneSignal.Debug.setLogLevel(6);
            window.plugins.OneSignal.initialize(oneSignalKey);
            window.plugins.OneSignal.Notifications.requestPermission();
            // this.requestPermission();
            // console.log(String(userID));
            // console.log(oneSignalKey);
            // window.plugins.OneSignal.logout();
            // const passToNativeParams = [userID];
            // passToNativeParams.push(userIDHash);
            console.log('oneSignalKey');
            console.log(oneSignalKey);
            window.plugins.OneSignal.login(String(userID));
            window.plugins.OneSignal.Session.addUniqueOutcome(String(userID));
            // window.plugins.OneSignal.User.setLanguage('en');
            window.plugins.OneSignal.User.getExternalId().then((id) => {
                console.log('window.plugins.OneSignal.getExternalId()');
                console.log(id);
            });
            window.plugins.OneSignal.User.getOnesignalId().then((id) => {
                console.log('window.plugins.OneSignal.getOnesignalId()');
                console.log(id);
            });
            // window.plugins.OneSignal.User.pushSubscription.optIn();
        },

using like

if (this.Capacitor.isNativePlatform()) {
            App.getInfo().then((app) => {
                if (app.build >= 4) {
                    document.addEventListener(
                        'deviceready',
                        this.OneSignalInit.bind(
                            null,
                            this.user.one_signal.key,
                            this.user.id,
                        ),
                        false,
                    );
                } else {
                    document.addEventListener(
                        'deviceready',
                        this.OneSignalInitLegacy.bind(
                            null,
                            this.user.one_signal.key,
                            this.user.id,
                            this.user.one_signal.hashes.id,
                        ),
                        false,
                    );
                }
            });
        }

How to fix this? Please assist



### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

<!-- probot = {"onesignal-probot":{"response_time_in_business_days":1}} -->
websitevirtuoso commented 6 months ago

Solution found https://github.com/OneSignal/react-onesignal/issues/121 can be closed. but would be great it we could add https://documentation.onesignal.com/docs/identity-verification

into v5.