Add QControllerV1 usage and setGotAuthenticationInAllControllers method to replace calling it on each controller instance

This commit is contained in:
2025-05-29 08:58:58 -05:00
parent 07d116d9ba
commit 96bdcf1874
4 changed files with 23 additions and 4 deletions

View File

@ -48,7 +48,7 @@ export default function useAnonymousAuthenticationModule({setIsFullyAuthenticate
{
console.log("Generating random token...");
setIsFullyAuthenticated(true);
qController.setGotAuthentication();
Client.setGotAuthenticationInAllControllers();
setCookie(SESSION_UUID_COOKIE_NAME, Md5.hashStr(`${new Date()}`), {path: "/"});
console.log("Token generation complete.");
};

View File

@ -30,6 +30,7 @@ import {useCookies} from "react-cookie";
import {useNavigate, useSearchParams} from "react-router-dom";
const qController = Client.getInstance();
const qControllerV1 = Client.getInstanceV1();
interface Props
{
@ -131,7 +132,7 @@ export default function useAuth0AuthenticationModule({setIsFullyAuthenticated, s
}
setIsFullyAuthenticated(true);
qController.setGotAuthentication();
Client.setGotAuthenticationInAllControllers();
setLoggedInUser(auth0User);
console.log("Token load complete.");

View File

@ -80,7 +80,7 @@ export default function useOAuth2AuthenticationModule({setIsFullyAuthenticated,
console.log(`we have new session UUID: ${newSessionUuid}`);
setIsFullyAuthenticated(true);
qController.setGotAuthentication();
Client.setGotAuthenticationInAllControllers();
setLoggedInUser(values?.user);
console.log("Token load complete.");
@ -109,7 +109,7 @@ export default function useOAuth2AuthenticationModule({setIsFullyAuthenticated,
const {values} = await qController.manageSession(null, sessionUuid, null);
setIsFullyAuthenticated(true);
qController.setGotAuthentication();
Client.setGotAuthenticationInAllControllers();
setLoggedInUser(values?.user);
console.log("Token load complete.");

View File

@ -20,6 +20,7 @@
*/
import {QController} from "@kingsrook/qqq-frontend-core/lib/controllers/QController";
import {QControllerV1} from "@kingsrook/qqq-frontend-core/lib/controllers/QControllerV1";
import {QException} from "@kingsrook/qqq-frontend-core/lib/exceptions/QException";
/*******************************************************************************
@ -29,6 +30,7 @@ import {QException} from "@kingsrook/qqq-frontend-core/lib/exceptions/QException
class Client
{
private static qController: QController;
private static qControllerV1: QControllerV1;
private static unauthorizedCallback: () => void;
private static handleException(exception: QException)
@ -54,6 +56,22 @@ class Client
return this.qController;
}
public static getInstanceV1(path: string = "/qqq/v1")
{
if (this.qControllerV1 == null)
{
this.qControllerV1 = new QControllerV1(path, this.handleException);
}
return this.qControllerV1;
}
public static setGotAuthenticationInAllControllers()
{
Client.getInstance().setGotAuthentication();
Client.getInstanceV1().setGotAuthentication();
}
static setUnauthorizedCallback(unauthorizedCallback: () => void)
{
Client.unauthorizedCallback = unauthorizedCallback;