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

Update user table during login/logout #605

Open
sezaru opened this issue Mar 2, 2021 · 0 comments
Open

Update user table during login/logout #605

sezaru opened this issue Mar 2, 2021 · 0 comments

Comments

@sezaru
Copy link

sezaru commented Mar 2, 2021

In my system, I store an FCM token (android push notification token) per user which I use to send period notifications to my clients.

So, for example, let's say I want to send notification A every hour, for that, I create a process that will first load all the tokens from clients that are interested in receiving these notifications and then manage that list.

The issue here is that I don't want to send notifications to users that had logged-out and users that had their renew token expired.

To achieve that, I thought about having a DB flag that makes me know if a user is logged in or out easily, so I created the field is_logged? in my user table.

With that, when I start the process to send notification A, it will query for the tokens of only the users that are really logged in.

Now what is missing is how to update that flag via Pow. This is what I'm thinking would be the way to go:

  • In the put function for the pow backend (I use the Postgres one, but I guess it would be the same as the mnesia one), I would update the user table changing the is_logged? flag to true before the client response and after the Pow.Plug.authenticate_user call;
  • In the delete function for the pow backend, I would need to update the is_logged? flag to false right after deleting the expired sessions for that user.

Since I'm using the Postgres backend for Pow, I think I can fork it and make these changes inside a Multi to guarantee atomicity.

So, this is more a question if my approach is a good one, if there is some corner case that I didn't thought about, and if you perhaps have some other better suggestion.

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

1 participant