Is it possible to get authentication events like l...
# prisma-whats-new
a
Is it possible to get authentication events like login and log out in a subscription? I’m not sure what to subscribe to as there are no node changes.
@nilan any input? 😛
n
Interesting use case! You can make it work by managing an additional field like "lastLogin". A problem with "logout" is that the API is stateless
so from the API standpoint, a user cannot be considered logged in or not. Instead, a request can be considered authenticated or not
if you're fine with subscribing to someone clicking the logout button, you can use the same approach as with "lastLogin". does this make sense?
a
Yeah, good idea, that should work! I’m using Auth0 and I believe their tokens last several hours so I think something like “lastLogin” might be the way to go.
Wait, so there’s no way to catch a logout unless it’s by the click of a button?
n
Again, the API does not consider users to be logged in or not. All it knows is tokens 🙂
What's the definition of a user being logged out in your application?
a
If the user clicked the log out button – which rarely happens – or if the token expired 😛
n
The first is something you can easily track. The second is a bit more difficult, because you can easily issue new tokens.
I think it's a fair approach to only track the first.
a
Yeah fair point. But just to make sure, so there’s no way to check if props.data.user is still valid?
n
oh, there is! if it's
null
, the token is not valid anymore 🙂
a
So if the user is still logged in in another tab or something, a refresh should be enough to fix it, yeah?
n
that depends on how and where you obtain the token
typically, it wouldn't fix it