Description
Introduction
Being able to disable a user so he can no longer use the login function without removing the user object.
Motivation
Disabling a user allows you to temporarily remove access to his account without removing all links or ACL's on existing objects. This way the user could be re-enabled in the future and still have access to his old objects.
Proposed solution
-
Add a flag to the
User
class that says if the user is disabled or not. TheUsersRouter
could be enhanced to take this flag into account. -
Another, more flexible, option would be to allow an override for the
UsersController
and inject that into theUsersRouter
handleLogin
flow. This way the developer can come up with custom flags to prevent a user from logging in, but this may be overkill.
Detailed design
-
Expand the
User
schema with aenabled
ordisabled
flag in theSchemaController
. Check for this flag in thehandleLogin
method of theUsersRouter
. -
Inject a
allowLogin
hook from theUsersController
into thehandleLogin
method of theUsersRouter
that returns aboolean
. A developer would implement his own version of theUsersController
and override thisallowLogin
method.
Alternatives considered
-
Using a Cloud Code function to handle the login and return a session token. You could use the
become
method on the client to login. However this prevents developers from using the normallogin
methods, and doesn't prevent a malicious user to still use the regularlogin
method that doesn't take the extra check into account. -
Account lockout: this is only a temporary measure where the account is disabled for a fixed amount of time and also serves another purpose than what is wanted here.
I tested a basic implementation of this proposal on my own fork. However it's still missing unit tests, and I don't know if this is functionality that could be used broadly.