diff --git a/actions/core/logger.js b/actions/core/logger.js index 13d35389..15c820b8 100644 --- a/actions/core/logger.js +++ b/actions/core/logger.js @@ -104,3 +104,18 @@ export const conLog = (err) => { console.log(errStr); return errStr; }; + +export const logInfo = (event, data = {}) => { + try { + console.info( + JSON.stringify({ + level: "info", + event, + data: redactSensitive(data), + ts: new Date().toISOString() + }) + ); + } catch (_error) { + console.info(`[info] ${event}`); + } +}; diff --git a/components/header.js b/components/header.js index 090dacd9..caa69f4a 100644 --- a/components/header.js +++ b/components/header.js @@ -2,12 +2,12 @@ import _ from "lodash"; import useTranslation from "next-translate/useTranslation"; import Link from "next/link"; import { useRouter } from "next/router"; -import { destroyCookie, setCookie } from "nookies"; +import { setCookie } from "nookies"; import { connect } from "react-redux"; import Banner from "../components/banner"; import { setLogout } from "../store/accountDetails/action"; -import { signOut } from "next-auth/react"; +import { logoutClient } from "../lib/auth/logoutClient"; const Header = (props) => { let { t, lang } = useTranslation(); @@ -85,14 +85,7 @@ const Header = (props) => { const handleLogout = () => { console.info("////////////\n" + "logout" + "\n////////////"); - (window.localStorage.clear(), - destroyCookie(null, "next-auth.csrf-token", { path: "/" }), - destroyCookie(null, "next-auth.callback-url", { path: "/" }), - destroyCookie(null, "pedw_locale", { path: "/" }), - destroyCookie(null, "pinsUser", { path: "/" }), - signOut({ - callbackUrl: locale == "cy" ? "/cy/allgofnodi" : "/logout" - })); + logoutClient(locale); }; //const switchLocale = locale === "en" ? "cy" : "en"; diff --git a/components/myportal/servicebanner.js b/components/myportal/servicebanner.js index 6f6768e1..3c6d2403 100644 --- a/components/myportal/servicebanner.js +++ b/components/myportal/servicebanner.js @@ -1,41 +1,22 @@ import useTranslation from "next-translate/useTranslation"; import router from "next/router"; import Link from "next/link"; -import { destroyCookie } from "nookies"; -import { signOut } from "next-auth/react"; +import { logoutClient } from "../../lib/auth/logoutClient"; const ServiceBanner = (props) => { props = props.props; let { t, lang } = useTranslation(); - const signInButton = () => { - router.push( - `${ - router.locale == "cy" ? "/awd/mewngofnodi" : "/auth/signin" - }?callbackUrl=${encodeURIComponent( - window.location.href - )}&error=EmailSignin` - ); - }; - const handleLogout = (locale) => { console.info("////////////\n" + "logout" + "\n////////////"); - window.localStorage.clear(), - destroyCookie(null, "next-auth.csrf-token"), - { path: "/" }, - destroyCookie(null, "next-auth.callback-url", { path: "/" }), - destroyCookie(null, "pedw_locale", { path: "/" }), - destroyCookie(null, "pinsUser", { path: "/" }), - signOut({ - callbackUrl: locale == "cy" ? "/cy/allgofnodi" : "/logout", - }); + logoutClient(locale); }; const portalLogoLink = [ "/myportal/[appealtypes]", "/newappeal", "/newappeal/[appealtypes]", - "/myportal/representation", + "/myportal/representation" ]; return (
diff --git a/components/timeout/index.js b/components/timeout/index.js index 76f56ab3..30a47d67 100644 --- a/components/timeout/index.js +++ b/components/timeout/index.js @@ -1,10 +1,8 @@ -import { signOut } from "next-auth/react"; import useTranslation from "next-translate/useTranslation"; import { useRouter } from "next/router"; -import { destroyCookie } from "nookies"; import { useState, useEffect } from "react"; import { useIdleTimer } from "react-idle-timer"; -import TimeoutModal from "./timeoutmodal"; +import { logoutClient } from "../../lib/auth/logoutClient"; const TimeOut = (props) => { let { t } = useTranslation(); @@ -21,14 +19,7 @@ const TimeOut = (props) => { const onIdle = () => { setState("Idle"); console.info("////////////\n" + "logout" + "\n////////////"); - window.localStorage.clear(), - destroyCookie(null, "next-auth.csrf-token", { path: "/" }), - destroyCookie(null, "next-auth.callback-url", { path: "/" }), - destroyCookie(null, "pedw_locale", { path: "/" }), - destroyCookie(null, "pinsUser", { path: "/" }), - signOut({ - callbackUrl: locale == "cy" ? "/cy/allgofnodi" : "/logout", - }); + logoutClient(locale); setOpen(false); }; @@ -48,7 +39,7 @@ const TimeOut = (props) => { onPrompt, timeout, promptBeforeIdle, - throttle: 500, + throttle: 500 }); useEffect(() => { @@ -89,14 +80,14 @@ const TimeOut = (props) => {

{t("common:login-modal-message", { - remaining: remaining, + remaining: remaining })}