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

[Question]: how to check if a user has logged in? (160001) #1090

Closed
lmeurs opened this issue Aug 18, 2023 · 2 comments
Closed

[Question]: how to check if a user has logged in? (160001) #1090

lmeurs opened this issue Aug 18, 2023 · 2 comments

Comments

@lmeurs
Copy link

lmeurs commented Aug 18, 2023

How can we help?

After a user logs in we want to initialize this user: 1) set an extra user alias, 2) set user language and 3) add multiple tags. For security reasons, we want to do these kind of operations as much as possble through server side API calls, eg.:

OneSignal.login(userId).then(function() {
  const response = await fetch('/api/user/connect?userId=' + userId);
  // ...
});

We have learnt that function OneSignal.login only needs to be called once. How can we check whether a user has already logged in? This would also prevent duplicate initialization. We could not find a method for this or a way to read a user's external ID or aliasses.

Or is there a better way to initialize users? We could not find eg. a user.created webhook (https://documentation.onesignal.com/docs/webhooks).

@jkasten2
Copy link
Member

@lmeurs Thanks for the question!

We have learnt that function OneSignal.login only needs to be called once. How can we check whether a user has already logged in? This would also prevent duplicate initialization.

You may call OneSignal.login on every page load or just once, the SDK accounts for both use-cases this so it won't cause any issues.

We could not find a method for this or a way to read a user's external ID or aliasses.

Most of the SDK's APIs are write-only, this is to encourage your operations / data to be the source of truth. The SDK caches operations (functions you call) and ensures they are completed (accounts for network issues). However we understand that a success confirmation is important, so we are looking into providing a way in the future to get the success result. Let us know if you have any concerns of feedback for this.

Or is there a better way to initialize users? We could not find eg. a user.created webhook (https://documentation.onesignal.com/docs/webhooks).

The WebSDK webhooks only support notification events.

@lmeurs
Copy link
Author

lmeurs commented Aug 18, 2023

As explained at #1094 (comment), we are trying to initialize a OneSignal user after loggin in. Without knowing client side whether a user has logged in or has been initialized, we do an API request to one of our endpoints, which does API requests to your endpoints. These requests can be skipped if we could tell client side whether a user is logged in or not.

If no method available, we can track a successful login + initialization using local storage as a workaround.

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