Skip to content
Gravity Logo / Docs Gravity home
Browse documentation
Documentation/Gravity Server

Authentication

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.

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:

KeyValueDescription
jwt_tokentrue or falsedetermines if the user has an active JWT

social_token

true or falsedetermines of the user has an active access token from a social network
subscriptionstringreturns the stripe subscription status
accountsarraythe accounts the user belongs to
account_idUUIDthe currently authenticated account id
authenticatedtrue or falsetrue 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