The sign in authentication process is managed in the authController located in /controller directory.
This method checks that:
the user exists
the correct password has been provided
an active subscription exists
the account is active
If these conditions are met, an auth token is generated and returned to the client along with the user permission level, name and subscription.
The authentication model is located in /model directory and contains several methods for encoding and decoding the JSON web token.
Users can sign in using their username or password, or via a magic link that sends a time-sensitive JWT for authentication.
Each sign in attempt is stored in the login table along with the device, browser and IP address. On each login attempt, the authController checks this table to check for suspicious activity based on past behaviour. If the IP address, device or browser differs from what the user normally uses to sign in, they will be notified via email.
If all three parameters (IP, browser and device) differ from past behaviour. The user's account will be disabled and the sign-in attempt blocked. The user will then receive a magic sign-in link via email to sign-in and unlock their account.