reps raised with correct return url

This commit is contained in:
2023-10-25 10:33:08 +01:00
parent fdf5be3415
commit f3da69dc75
5 changed files with 61 additions and 52 deletions
+1 -1
View File
@@ -603,7 +603,7 @@ let MakeRepresentation = (props) => {
<button
className="govuk-button withChevron govuk-button-cta"
type="button"
onClick={() => signIn("email")}
onClick={() => signIn()}
>
Sign in to raise representation
</button>
+16 -21
View File
@@ -155,14 +155,7 @@ const authOptions = (locale, req) => {
const personalisation = {
"emailAddress": email,
"signInLink": url,
"signInLink":
newURL +
"/api/auth/callback/email?callbackUrl=" +
encodeURIComponent(newURL) +
"&token=" +
searchParams.get("token") +
"&email=" +
encodeURIComponent(email),
"linkExpiry": 10 * 60,
};
const reference = "PEDW-SIGNIN";
@@ -220,19 +213,21 @@ const authOptions = (locale, req) => {
//console.log(user);
return Promise.resolve(session);
},
async redirect({ url, baseUrl }) {
// // Allows relative callback URLs
// if (url.startsWith("/")) return `${baseUrl}${url}`;
// // Allows callback URLs on the same origin
// else if (new URL(url).origin === baseUrl) return url;
let newURL =
locale == "cy"
? process.env.CY_API_ROOT
: process.env.NEXTAUTH_URL;
//console.log("baseurl:", newURL);
//return baseUrl;
return newURL;
},
// redirect({ url, baseUrl }) {
// debugger;
// console.log("baseurl:", url, baseUrl);
// // Allows relative callback URLs
// if (url.startsWith("/")) return `${baseUrl}${url}`;
// // Allows callback URLs on the same origin
// else if (new URL(url).origin === baseUrl) return url;
// // let newURL =
// // locale == "cy"
// // ? process.env.CY_API_ROOT
// // : process.env.NEXTAUTH_URL;
// //return baseUrl;
// // return newURL;
// },
},
};
};
+35 -23
View File
@@ -43,7 +43,7 @@ const SignIn = (props) => {
<div className="govuk-grid-column-two-thirds ">
<form
method="post"
action={"/api/auth/signin/email"}
action="/api/auth/signin/email"
>
<div className="govuk-form-group">
<input
@@ -90,32 +90,44 @@ const SignIn = (props) => {
);
};
// export async function getServerSideProps(context) {
// //console.log("-1-1-1-1-", context.query.callbackUrl, context.locale);
// //console.log("------ " + context.query.callbackUrl);
// // setCookie(context, "next-auth.callback-url", context.query.callbackUrl, {
// // path: "/",
// // });
// const csrfToken = await getCsrfToken(context);
// let callback =
// context.locale != "cy"
// ? process.env.NEXTAUTH_URL
// : "https://" + process.env.I18N_DOMAIN + ":3000";
// context.query.callbackUrl = callback;
// let formURL =
// new URL(callback).protocol +
// "//" +
// new URL(callback).hostname +
// ":" +
// new URL(callback).port; // +
// // "/api/auth/signin/email";
// //console.log("******", formURL, callback, csrfToken);
// return {
// props: { csrfToken: csrfToken, callbackUrl: formURL, redirect: true },
// };
// }
export async function getServerSideProps(context) {
//console.log("-1-1-1-1-", context.query.callbackUrl, context.locale);
//console.log("------ " + context.query.callbackUrl);
// setCookie(context, "next-auth.callback-url", context.query.callbackUrl, {
// path: "/",
// });
const csrfToken = await getCsrfToken(context);
let callback =
context.locale != "cy"
? process.env.NEXTAUTH_URL
: "https://" + process.env.I18N_DOMAIN + ":3000";
console.log("-1-1-1-1-", context.query.callbackUrl, context.locale);
let formURL = context.query.callbackUrl;
console.log("formUrl:", formURL);
context.query.callbackUrl = callback;
let formURL =
new URL(callback).protocol +
"//" +
new URL(callback).hostname +
":" +
new URL(callback).port; // +
// "/api/auth/signin/email";
//console.log("******", formURL, callback, csrfToken);
formURL = typeof formURL == "undefined" ? null : formURL;
return {
props: { csrfToken: csrfToken, callbackUrl: formURL, redirect: true },
props: { csrfToken: csrfToken, callbackUrl: formURL },
};
}
+8 -6
View File
@@ -10,7 +10,7 @@ import Footer from "../../components/footer";
import Header from "../../components/header";
import Case from "../../components/representation";
import { wrapper } from "../../store/store";
import { getSession, useSession } from "next-auth/react";
import { getSession, useSession, signIn } from "next-auth/react";
import {
consoleLogger,
getPersonalAccount,
@@ -69,11 +69,13 @@ const Home = (props) => {
if (status === "loading") {
return <NoSessionWarning loading={true} />;
}
if (status === "unauthenticated") {
router.push("/auth/signin");
return <NoSessionWarning />;
}
// console.log("unauthenticated path:", router.asPath);
// if (status === "unauthenticated") {
// console.log("unauthenticated path:", router.asPath);
// signIn("email", { callbackUrl: router.asPath });
// //router.push("/auth/signin");
// return <NoSessionWarning />;
// }
return (
<div>
+1 -1
View File
@@ -127,7 +127,7 @@ const makeStore = ({ isServer }) => {
key: "acp",
whitelist: [
"currentView",
//"searchResultsObj",
"searchResultsObj",
//"appealType",
"LPAData",
//"accountDetails",