login error and mutlitlingual login flow
This commit is contained in:
+41
-14
@@ -42,6 +42,7 @@ const Home = (props) => {
|
||||
hasGGCode,
|
||||
loginEmailStr,
|
||||
loggedInUserEmail,
|
||||
ggLocale,
|
||||
} = props;
|
||||
let { t, lang } = useTranslation();
|
||||
|
||||
@@ -71,7 +72,10 @@ const Home = (props) => {
|
||||
expires: expDate,
|
||||
}),
|
||||
router.replace({
|
||||
pathname: router.locale == "cy" ? "/fymhorth" : "/myportal",
|
||||
pathname:
|
||||
router.locale == "cy" || ggLocale == "cy"
|
||||
? "/cy/fymhorth"
|
||||
: "/myportal",
|
||||
}))
|
||||
: console.log("no value in user id");
|
||||
|
||||
@@ -131,13 +135,22 @@ const Home = (props) => {
|
||||
<div className="govuk-width-container">
|
||||
{hasGGCode ? (
|
||||
<>
|
||||
<h1>Logging in</h1>
|
||||
<h2>Please wait...</h2>
|
||||
<h1>
|
||||
{ggLocale == "cy"
|
||||
? "Mewngofnodi"
|
||||
: "Logging in"}
|
||||
</h1>
|
||||
<h2>
|
||||
{ggLocale == "cy"
|
||||
? "Arhoswch os gwelwch yn dda..."
|
||||
: "Please wait..."}
|
||||
</h2>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<ServiceBanner />
|
||||
<Main
|
||||
ggLocale={ggLocale}
|
||||
pages={pages}
|
||||
showLogin={showLogin}
|
||||
loggedInUserId={loggedInUserId}
|
||||
@@ -161,11 +174,14 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
relayToken = relayToken.access_token;
|
||||
|
||||
console.log("gg code:", query.code);
|
||||
console.log("gg local", query.ui_locales);
|
||||
|
||||
const showLoginCheck = process.env.SHOWLOGIN || false;
|
||||
|
||||
const hasLoginCode = typeof query.code != "undefined";
|
||||
let providerConfig = await getProviderConfig();
|
||||
let ggLocale =
|
||||
typeof query.ui_locales != "undefined" && query.ui_locales;
|
||||
|
||||
console.log(
|
||||
"endpoint: ",
|
||||
@@ -180,12 +196,13 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
|
||||
store.dispatch(getGovGatewayConfig(providerConfig));
|
||||
|
||||
let ggToken = {};
|
||||
let ggUserInfo = {};
|
||||
let portalUserObj = {};
|
||||
let loginEmailStr = "";
|
||||
|
||||
if (hasLoginCode == true) {
|
||||
const ggToken = await getGGToken(
|
||||
ggToken = await getGGToken(
|
||||
providerConfig.token_endpoint,
|
||||
query.code,
|
||||
process.env.GG_REDIRECT_URI
|
||||
@@ -208,16 +225,26 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
props: {
|
||||
showLogin: showLoginCheck,
|
||||
hasGGCode: hasLoginCode,
|
||||
loggedInUserId: portalUserObj,
|
||||
loggedInUserEmail: loginEmailStr,
|
||||
GG_REDIRECT_URI: process.env.GG_REDIRECT_URI,
|
||||
GG_CLIENT_ID: process.env.GG_CLIENT_ID,
|
||||
},
|
||||
};
|
||||
if (ggToken.status == 400) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/myportal/error",
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
props: {
|
||||
ggLocale: ggLocale,
|
||||
showLogin: showLoginCheck,
|
||||
hasGGCode: hasLoginCode,
|
||||
loggedInUserId: portalUserObj,
|
||||
loggedInUserEmail: loginEmailStr,
|
||||
GG_REDIRECT_URI: process.env.GG_REDIRECT_URI,
|
||||
GG_CLIENT_ID: process.env.GG_CLIENT_ID,
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import Link from "next/link";
|
||||
import Head from "next/head";
|
||||
import Header from "../../components/header";
|
||||
import Banner from "../../components/banner";
|
||||
import CookieBanner from "../../components/cookieBanner";
|
||||
import useTranslation from "next-translate/useTranslation";
|
||||
import Footer from "../../components/footer";
|
||||
|
||||
function Error({ statusCode }, props) {
|
||||
let { t, lang } = useTranslation();
|
||||
const { footerLinks, pages } = props;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Head>
|
||||
<title>
|
||||
{t("myportal:page-title")} - {t("common:service-name")}
|
||||
</title>
|
||||
</Head>
|
||||
<div id="page_wrapper">
|
||||
<CookieBanner />
|
||||
<Header courseName={t("common:service-name")} />
|
||||
<div className="govuk-width-container govuk-!-padding-bottom-9">
|
||||
<main className="govuk-main-wrapper govuk-!-padding-top-9 govuk-!-padding-bottom-9">
|
||||
<div className="govuk-grid-row">
|
||||
<div className="govuk-grid-column-two-thirds ">
|
||||
<h1>{t("common:error-page-title")}</h1>
|
||||
<p className="govuk-body">
|
||||
A problem occured when trying to login
|
||||
</p>
|
||||
<Link href="/">
|
||||
<a>{t("common:404-not-found-link")}</a>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
<Footer footerLinks={footerLinks} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Error.getInitialProps = ({ res, err }) => {
|
||||
const statusCode = res ? res.statusCode : err ? err.statusCode : 404;
|
||||
console.log(res, err);
|
||||
return { statusCode };
|
||||
};
|
||||
|
||||
export default Error;
|
||||
+34
-23
@@ -205,30 +205,41 @@ export const getServerSideProps = wrapper.getServerSideProps(
|
||||
_.has(accountDetails, "errorCode") != false
|
||||
);
|
||||
|
||||
const [
|
||||
myCasesDetails,
|
||||
myRepresentationsDetails,
|
||||
watchedCasesDetails,
|
||||
// awaitingSubmissionDetails,
|
||||
] = await Promise.all([
|
||||
await getDetails(token, myCases, "myCases"),
|
||||
await getDetails(token, myRepresentations, "myRepresentations"),
|
||||
await getDetails(token, watchedCases, "myWatchedCases"),
|
||||
// await getDetails(awaitingSubmission),
|
||||
]);
|
||||
if (_.has(accountDetails, "errorCode") != false) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/myportal/error",
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
} else {
|
||||
const [
|
||||
myCasesDetails,
|
||||
myRepresentationsDetails,
|
||||
watchedCasesDetails,
|
||||
// awaitingSubmissionDetails,
|
||||
] = await Promise.all([
|
||||
await getDetails(token, myCases, "myCases"),
|
||||
await getDetails(token, myRepresentations, "myRepresentations"),
|
||||
await getDetails(token, watchedCases, "myWatchedCases"),
|
||||
// await getDetails(awaitingSubmission),
|
||||
]);
|
||||
|
||||
store.dispatch(setAccountDetails(accountDetails));
|
||||
store.dispatch(setLoggedInUserId(loggedInUser));
|
||||
store.dispatch(setMyCases(myCases));
|
||||
store.dispatch(setMyCasesDetails(myCasesDetails));
|
||||
store.dispatch(setMyRepresentations(myRepresentations));
|
||||
store.dispatch(setMyRepresentationsDetails(myRepresentationsDetails));
|
||||
store.dispatch(setWatchedCases(watchedCases));
|
||||
store.dispatch(setWatchedCasesDetails(watchedCasesDetails));
|
||||
store.dispatch(setAwaitingSubmission(awaitingSubmission));
|
||||
// store.dispatch(
|
||||
// setAwaitingSubmissionDetails(awaitingSubmissionDetails)
|
||||
// );
|
||||
store.dispatch(setAccountDetails(accountDetails));
|
||||
store.dispatch(setLoggedInUserId(loggedInUser));
|
||||
store.dispatch(setMyCases(myCases));
|
||||
store.dispatch(setMyCasesDetails(myCasesDetails));
|
||||
store.dispatch(setMyRepresentations(myRepresentations));
|
||||
store.dispatch(
|
||||
setMyRepresentationsDetails(myRepresentationsDetails)
|
||||
);
|
||||
store.dispatch(setWatchedCases(watchedCases));
|
||||
store.dispatch(setWatchedCasesDetails(watchedCasesDetails));
|
||||
store.dispatch(setAwaitingSubmission(awaitingSubmission));
|
||||
// store.dispatch(
|
||||
// setAwaitingSubmissionDetails(awaitingSubmissionDetails)
|
||||
// );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user