Not able to get userID

31 Views Asked by At

I am trying to get player id but I am getting error-

[ReferenceError: Property 'userId' doesn't exist]

My code-

    useEffect(() => {
        OneSignal.setAppId('APP_ID');

        OneSignal.setNotificationOpenedHandler(notification => {
            console.log('Notification opened:', notification);
        });

        return () => {
            OneSignal.clearHandlers();
        };
    }, []);


OneSignal.setRequiresUserPrivacyConsent(false);
OneSignal.sendTag('userId', userId);

// Get the OneSignal player ID (device ID)
const oneSignalPlayerId = await OneSignal.getDeviceState();
const playerId = oneSignalPlayerId.userId;

console.log('playerId:', playerId);

Is there anything I am missing?

0

There are 0 best solutions below