The sign-in authentication process is managed in the authController.
This method checks that:
- the user exists
- the correct password has been provided
- the account is active
- the sign-in is not suspicious (see sections below for more information)
If these conditions are met, an auth token is generated and returned to the client along with a user object.
Authentication Model
The authentication model is located in /model directory and contains several methods for encoding and decoding the JSON web token and also the verify middleware for protecting the API endpoints.
Magic Sign-in Links
Users can sign in using their email address and password, or via a magic link that sends a time-sensitive JWT for authentication.
Suspicious Sign-In Attempts
The sign-in controller records the login and asks the login model to assess risk using the user’s previous logins. An unfamiliar sign-in can trigger an email when the user’s new_signin notification is enabled.
Blocked Sign-In Attempts
For a blocked sign-in, the server responds with HTTP 403 and sends the account recovery email. Follow the link in the email to regain access.
Check the Auth Status
The auth status of a user can be checked by making a GET request to /api/auth. This request is performed every time the app is loaded or reloaded.
The response has a data object with the following values:
| Key | Value | Description |
|---|---|---|
| jwt_token | true or false | determines if the user has an active JWT |
social_token | true or false | determines of the user has an active access token from a social network |
| subscription | string | returns the stripe subscription status |
| accounts | array | the accounts the user belongs to |
| account_id | UUID | the currently authenticated account id |
| authenticated | true or false | true if the user has an app JWT or social token |
Deleting Auth Tokens
You can sign out the user and delete the auth tokens by making a DELETE request to /api/auth