Skip to content

Auth API

This file contains functions to manage authentication-related operations such as login, logout, and service retrieval.

Functions

POST login(username, password)

Logs in a user with the provided credentials.

Input:

  • username (string): The username of the user.
  • password (string): The password of the user.

Output: Authentication token or error message.

Request Details:

  • URL: authService/auth/signin
  • Method: POST
  • Data:
    {
      "user": "username",
      "password": "password"
    }
    

POST logoutApi()

Logs out the currently logged-in user.

Input: None
Output: Confirmation of logout.

Request Details:

  • URL: authService/auth/logout
  • Method: POST
  • With Credentials: true

GET getServices()

Fetches all available services.

Input: None
Output: List of services.

Request Details:

  • URL: authService/service
  • Method: GET

isUserLoggedIn()

Checks if a user is currently logged in.

Input: None
Output: Boolean (true or false).


moveToPage(router, next, role)

Redirects the user to a specific page based on their role.

Input:

  • router (object): The router instance.
  • next (function): Callback function to execute after redirection.
  • role (string): The role of the user (Admin or other).

Output: None.


logout(router)

Logs out the user and redirects them to the login page.

Input:

  • router (object): The router instance.

Output: None.

Details:

  • Calls logoutApi() to perform the logout operation.
  • Removes the token cookie if an error occurs during logout.