1
Hello, I am trying to return the user’s unique browser ID to save that ID after notification permission is granted by the user in the browser.
I am using the lib React-onesignal and when I ask for the return of the ID the object returns null or prints nothing on the console. Also no return status, the point is that in the browser ta everything ok, permission is granted but the function is not returning this playerId
const Signal = async (): Promise<void> => {
OneSignal.initialize(`${process.env.NEXT_PUBLIC_ONE_SIGNAL_APP_ID}`, {
allowLocalhostAsSecureOrigin: true,
autoRegister: false,
notifyButton: {
prenotify: true,
},
})
const isPush = await OneSignal.isPushNotificationsEnabled()
if (!isPush) {
await OneSignal.registerForPushNotifications()
}
const permissions = OneSignal.notificationPermission
const currentState = await OneSignal.getNotificationPermission()
const playerId = await OneSignal.getPlayerId()
console.log(playerId)
console.log('State:', currentState)
console.log('Permissions:', permissions)
}
I believe that the initialization of Onesignal is correct, I just do not know what is missing so that is returning the user ID that is the information I need.