Phase 1 reliability/stabilisation: auth logging, logout client, loader+xml hardening
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { destroyCookie } from "nookies";
|
||||
import { signOut } from "next-auth/react";
|
||||
|
||||
const AUTH_COOKIE_NAMES = [
|
||||
"next-auth.csrf-token",
|
||||
"next-auth.callback-url",
|
||||
"__Secure-next-auth.callback-url",
|
||||
"pedw_locale",
|
||||
"pinsUser"
|
||||
];
|
||||
|
||||
export const clearClientSessionArtifacts = () => {
|
||||
if (typeof window !== "undefined") {
|
||||
window.localStorage.clear();
|
||||
}
|
||||
|
||||
AUTH_COOKIE_NAMES.forEach((cookieName) => {
|
||||
destroyCookie(null, cookieName, { path: "/" });
|
||||
});
|
||||
};
|
||||
|
||||
export const logoutClient = async (locale) => {
|
||||
clearClientSessionArtifacts();
|
||||
await signOut({
|
||||
callbackUrl: locale === "cy" ? "/cy/allgofnodi" : "/logout"
|
||||
});
|
||||
};
|
||||
@@ -2,6 +2,8 @@
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
const xmlCache = new Map();
|
||||
|
||||
/**
|
||||
* Reads /data/formsxml/{appealtypes}.xml and normalises it.
|
||||
* Returns { xmlStr } or throws on missing file.
|
||||
@@ -9,6 +11,10 @@ import path from "path";
|
||||
export function readFormXml(appealtypes) {
|
||||
if (!appealtypes) throw new Error("readFormXml: appealtypes is required");
|
||||
|
||||
if (xmlCache.has(appealtypes)) {
|
||||
return xmlCache.get(appealtypes);
|
||||
}
|
||||
|
||||
const configDirectory = path.resolve(process.cwd(), "data/formsxml");
|
||||
const filePath = path.join(configDirectory, `${appealtypes}.xml`);
|
||||
|
||||
@@ -20,5 +26,8 @@ export function readFormXml(appealtypes) {
|
||||
xmlStr = xmlStr.replace(/> <"/g, "><");
|
||||
xmlStr = xmlStr.toString();
|
||||
|
||||
return { xmlStr, filePath };
|
||||
const result = { xmlStr, filePath };
|
||||
xmlCache.set(appealtypes, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
} from "../../actions/services/referenceDataService";
|
||||
import { getProgressFromBlob } from "../../actions/services/documentService";
|
||||
import { getPersonalAccount } from "../../actions/services/accountService";
|
||||
import { getIP } from "../../actions/core/logger";
|
||||
import { getIP, logInfo, consoleLogger } from "../../actions/core/logger";
|
||||
import { readFormXml } from "../forms/readFormXml";
|
||||
import { requireQueryParams } from "../routing/requireQueryParams";
|
||||
|
||||
@@ -29,6 +29,10 @@ export async function loadNewAppealPage(ctx) {
|
||||
|
||||
const session = await getSession(ctx);
|
||||
if (!session) {
|
||||
logInfo("auth.guard.redirect", {
|
||||
route: "/newappeal/[appealtypes]",
|
||||
reason: "missing_session"
|
||||
});
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/auth/signin",
|
||||
@@ -52,7 +56,18 @@ export async function loadNewAppealPage(ctx) {
|
||||
const blobProgress = await getProgressFromBlob(loggedInUserIdent, query.id);
|
||||
const accountDetails = await getPersonalAccount(loggedInUser);
|
||||
|
||||
const { xmlStr } = readFormXml(query.appealtypes);
|
||||
let xmlStr = "";
|
||||
try {
|
||||
({ xmlStr } = readFormXml(query.appealtypes));
|
||||
} catch (error) {
|
||||
consoleLogger(error);
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/error?reason=formxml",
|
||||
permanent: false
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
session,
|
||||
|
||||
Reference in New Issue
Block a user