Skip to content

loginUtils

login (async)

Authenticates the user using the provided identifier and password. This asynchronous function sends a login request to the backend using the provided identifier and password. Upon successful authentication, it stores the received JWT token either in persistent or session storage, based on the rememberMe flag. It then redirects the user to the /signinsheet route. If the login fails, it returns an error message.

Parameters:

  • identifier: - The user's email or username.
  • password: - The user's password.
  • rememberMe: - Determines whether to store the JWT token persistently or in session storage.
  • router: - The Vue Router instance used for navigation.

Returns:

  • object containing the success status and a message detailing the result of the login attempt.

logout (async)

Logs the user out by removing the JWT token from both persistent and session storage and redirects them to the login page.

Parameters:

  • router: - The Vue Router instance used for navigation.

Returns:

  • object containing the success status and a message detailing the result of the logout attempt.

isTokenValid (async)

Validates the current JWT token to determine its validity and the user's login status. If the user has logged in as a 'hare', the token is considered valid without further checks. If no token is found, or if the token is invalid or expired, it returns a validation failure. When offline, it treats the token as valid but unverified. If online, it verifies the token against the backend by fetching user data.

Returns:

  • object containing: - valid (boolean): Indicates if the token is valid. - user (object|null): User data if the token is valid, otherwise null. - reason (string|null): Reason for invalidity, or null if valid.

Released under the MIT License.