Documentation

Module: Auth.js

Description: This module provides authentication and session management functionalities for the application. It utilizes react-secure-storage for secure local storage and interacts with the API for authentication and authorization.

Functions


Function: parseRequest

Description: Parses the URL search parameters and returns a URLSearchParams object.

Parameters: None

Returns:

  • URLSearchParams: An object containing the parsed URL search parameters.

Example:

const params = parseRequest();
const userId = params.get('userId');

Function: updateSessionFromJWT

Description: Updates the user session with information from a provided JWT.

Parameters:

  • jwt (string): The JWT string containing session information.

Returns:

  • void

Example:

const jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw0";
updateSessionFromJWT(jwt);

Function: authenticate

Description: Authenticates the user with the specified provider.

Parameters:

  • provider (string): The authentication provider (e.g., "github"). Defaults to "github".
  • code (string): The authorization code obtained from the authentication provider.

Returns:

  • boolean: true if authentication is successful, false otherwise.

Example:

const isAuthenticated = await authenticate("github", code);

Function: reauthenticate

Description: Reauthneticates the user using their refresh token.

Parameters: None

Returns:

  • boolean: true if reauthentication is successful, false otherwise.

Example:

const isAuthenticated = await reauthenticate();

Function: isAuthenticated

Description: Checks if the user is currently authenticated.

Parameters: None

Returns:

  • boolean: true if the user is authenticated, false otherwise.

Example:

if (isAuthenticated()) {
  // Show authenticated content
} else {
  // Redirect to login page
}

Function: isOutdated

Description: Checks if the current session is outdated based on the build SHA.

Parameters: None

Returns:

  • boolean: true if the session is outdated, false otherwise.

Example:

if (isOutdated()) {
  // Update the session
}

Function: getJwt

Description: Retrieves the JWT from the current session.

Parameters: None

Returns:

  • string: The JWT string, or null if not available.

Example:

const jwt = getJwt();

Function: getAccessToken

Description: Retrieves the access token from the current session.

Parameters: None

Returns:

  • string: The access token string, or null if not available.

Example:

const accessToken = getAccessToken();

Function: updateSession

Description: Updates the current session with new information.

Parameters:

  • session (object): The new session data.

Returns:

  • void

Example:

const newSession = {
  user: { name: "John Doe" },
  build: { CommitHash: "abcdef1234567890" }
};
updateSession(newSession);

Function: getSession

Description: Retrieves the current session data from local storage.

Parameters: None

Returns:

  • object: The session data, or null if not available.

Example:

const session = getSession();

Function: logout

Description: Logs the user out and clears the session data.

Parameters:

  • msg (string): Optional message to display on logout. Defaults to null.

Returns:

  • void

Example:

logout("Logging out...");

Function: _setSession

Description: Saves the session data to local storage. This function is internal and is not intended to be called directly.

Parameters:

  • session (object): The session data to save.

Returns:

  • void

Example: None. This is an internal function.