updated authentication for welsh url
This commit is contained in:
+43
-2
@@ -148,12 +148,53 @@ export async function getServerSideProps(context) {
|
||||
context.locale,
|
||||
"\n//////////////////////\n"
|
||||
);
|
||||
let formURL = context.query.callbackUrl;
|
||||
let formURL = context.req.headers.host;
|
||||
//console.log("formUrl:", formURL);
|
||||
|
||||
formURL = typeof formURL == "undefined" ? null : formURL;
|
||||
|
||||
let protocol = "http";
|
||||
if (context.req.headers["x-forwarded-proto"]) {
|
||||
protocol = context.req.headers["x-forwarded-proto"];
|
||||
}
|
||||
// Otherwise, check if the connection is encrypted (for https)
|
||||
else if (context.req.connection.encrypted) {
|
||||
protocol = "https";
|
||||
}
|
||||
|
||||
formURL = protocol + "://" + formURL;
|
||||
|
||||
console.log("Protocol:", protocol);
|
||||
console.log("locale:", context.locale);
|
||||
|
||||
const appendParamsAndPathToNewUrl = (fromUrl, toUrl) => {
|
||||
const fromUrlObj = new URL(fromUrl); // Parse the source URL
|
||||
const params = fromUrlObj.searchParams; // Extract the query parameters
|
||||
|
||||
const toUrlObj = new URL(toUrl); // Parse the new domain URL
|
||||
toUrlObj.pathname = fromUrlObj.pathname; // Copy the path from the source URL
|
||||
|
||||
// Append the query parameters to the new URL
|
||||
params.forEach((value, key) =>
|
||||
toUrlObj.searchParams.append(key, value)
|
||||
);
|
||||
|
||||
return toUrlObj.toString(); // Return the full new URL as a string
|
||||
};
|
||||
|
||||
formURL = appendParamsAndPathToNewUrl(context.query.callbackUrl, formURL);
|
||||
|
||||
const url = new URL(formURL); // base URL
|
||||
|
||||
const params = new URLSearchParams(url.search);
|
||||
params.append("locale", context.locale);
|
||||
|
||||
url.search = params.toString();
|
||||
|
||||
console.log("========== callback: ", url.toString());
|
||||
|
||||
return {
|
||||
props: { csrfToken: csrfToken, callbackUrl: formURL },
|
||||
props: { csrfToken: csrfToken, callbackUrl: url.toString() },
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+26
-4
@@ -219,16 +219,38 @@ export async function getServerSideProps(context) {
|
||||
const csrfToken = await getCsrfToken(context);
|
||||
console.log(
|
||||
"\n//////////////////////\n",
|
||||
"Sign in callbackurl: " + context.query.callbackUrl,
|
||||
"Sign in callbackurl: " + context.req.headers.host,
|
||||
context.locale,
|
||||
csrfToken + "\n//////////////////////\n"
|
||||
);
|
||||
let formURL = context.query.callbackUrl;
|
||||
//console.log("formUrl:", formURL);
|
||||
let formURL = context.req.headers.host;
|
||||
console.log("formUrl:", formURL);
|
||||
|
||||
formURL = typeof formURL == "undefined" ? null : formURL;
|
||||
|
||||
let protocol = "http";
|
||||
if (context.req.headers["x-forwarded-proto"]) {
|
||||
protocol = context.req.headers["x-forwarded-proto"];
|
||||
}
|
||||
// Otherwise, check if the connection is encrypted (for https)
|
||||
else if (context.req.connection.encrypted) {
|
||||
protocol = "https";
|
||||
}
|
||||
|
||||
formURL = protocol + "://" + formURL;
|
||||
|
||||
console.log("Protocol:", protocol);
|
||||
console.log("locale:", context.locale);
|
||||
|
||||
const url = new URL(formURL); // base URL
|
||||
|
||||
const params = new URLSearchParams(url.search);
|
||||
params.append("locale", context.locale);
|
||||
|
||||
url.search = params.toString();
|
||||
|
||||
return {
|
||||
props: { csrfToken: csrfToken, callbackUrl: formURL },
|
||||
props: { csrfToken: csrfToken, callbackUrl: url.toString() },
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user