Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing App User not working OneSignal.removeExternelUserId() #733

Closed
sayedbilalhussain opened this issue Dec 11, 2020 · 3 comments
Closed

Comments

@sayedbilalhussain
Copy link

sayedbilalhussain commented Dec 11, 2020

I'm trying to Logging out app user by calling OneSignal.removeExternalUserId(); but my user is still taking notifications
and when i debugged this App is still having same user id .
image is attached the message i'm receiving .Please guide me what i'm doing wrong?
image
My Code is

$(document).ready(function() {
    // console.log('Test', typeof OneSignal , typeof OneSignal)
    // if(typeof window.OneSignal === "undefined"){
    // }
        var OneSignal = window.OneSignal || [];

    OneSignal.push(["init", {
        appId: ONESIGNAL_APP_ID,
        subdomainName: "",
        autoRegister: true,
        promptOptions: {
            actionMessage: "We'd like to show you notifications for the latest orders",
            acceptButtonText: "ALLOW",
            cancelButtonText: "NO THANKS"
        }
    }]);


    // var OneSignal = OneSignal || [];
    OneSignal.push(function(){

        console.log("User id to save in OS: "+USER_ID)
        OneSignal.setExternalUserId(USER_ID);

        OneSignal.on('subscriptionChange', function(isSubscibed){
            console.log("The user's subscription state is now", isSubscibed);

            /*OneSignal.sendTag("user_id","4444", function(tagsSent) {
                console.log("Tags have finished sending!");
            });*/
        });

        var isPushSupported = OneSignal.isPushNotificationsSupported();
        if(isPushSupported)
        {
            OneSignal.getUserId( function(userId) {
                /* $.ajaxSetup({
                     headers: {
                         'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                     }
                 });

                 $.ajax({
                     type:'POST',
                     url: '/user/push',
                     dataType: 'json',
                     data: { userId: userId},
                     success:function(response){
                         if(response.status){
                            alert(response.userId)
                         }
                     }, error: function (response) {
                        //alert(response.responseJSON.errMsg);
                     }
                 })*/
                console.log("userId", userId);
            });

            OneSignal.isPushNotificationsEnabled().then(function(isEnabled)
            {
                if(isEnabled)
                {
                    //console.log(OneSignal)
                    console.log("Push nofitications are enabled");
                }else {
                    OneSignal.showHttpPrompt();
                    console.log("Push notifications are not enabled yet.");
                }
            });

        }else{
            console.log("Push notifications are not supported.");
        }
    });
    //logout if user_id is empty
    if (USER_ID == ""){
        OneSignal.removeExternalUserId();
    }
});
@rgomezp
Copy link
Contributor

rgomezp commented Feb 25, 2022

Howdy,
Sorry for the late reply. Can you please let us know if this is still an issue for you?

Cheers

@rgomezp
Copy link
Contributor

rgomezp commented Mar 10, 2022

Closing for now. Please leave a comment if you are still seeing this issue and we can reopen

@rgomezp rgomezp closed this as completed Mar 10, 2022
@Kudratullah
Copy link

Hi this issue is still on.
OneSignal.removeExternalUserId() rejects with changing external_user_id on players require passing external_user_id_auth_hash
As I dig into the source and found OneSignal.privateSetExternalUserId() (called by removeExternalUserId) requires 2 argument externalUserId, authHash, but removeExternalUserId doesn't provide auth-hash.
i tested calling await OneSignal.privateSetExternalUserId(undefined, 'auth-hash'); directly and it work as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants