Add logging

This commit is contained in:
Eduard Gert
2024-04-03 13:33:58 +02:00
parent 6d4716cdad
commit 97255dd882
3 changed files with 11 additions and 4 deletions

View File

@@ -34,7 +34,7 @@ const auth0AuthorityConfig: AuthorityConfiguration = {
const onEvent = (configurationName: any, eventName: any, data: any) => {
if (process.env.NODE_ENV !== "production") {
//console.info(`oidc:${configurationName}:${eventName}`, data);
console.info(`oidc:${configurationName}:${eventName}`, data);
}
};

View File

@@ -1,4 +1,5 @@
import { OidcSecure, useOidc } from "@axa-fr/react-oidc";
import loadConfig from "@utils/config";
import { usePathname } from "next/navigation";
import * as React from "react";
import { useEffect } from "react";
@@ -6,13 +7,18 @@ import { useEffect } from "react";
type Props = {
children: React.ReactNode;
};
const config = loadConfig();
export const SecureProvider = ({ children }: Props) => {
const { isAuthenticated, login } = useOidc();
const currentPath = usePathname();
useEffect(() => {
console.log("isAuthenticated", isAuthenticated);
if (!isAuthenticated) {
login(currentPath);
console.info("Not authenticated, logging in...");
login(currentPath, { client_id: config.clientId });
}
}, [currentPath, isAuthenticated, login]);

View File

@@ -160,11 +160,12 @@ export function useApiErrorHandling(ignoreError = false) {
};
return (err: ErrorResponse) => {
console.info("API request error", err);
if (err.code == 401 && err.message == "no valid authentication provided") {
return login(currentPath);
return login(currentPath, { client_id: config.clientId });
}
if (err.code == 401 && err.message == "token expired") {
return login(currentPath);
return login(currentPath, { client_id: config.clientId });
}
if (err.code == 401 && err.message == "token invalid") {
return setError(err);