basepath for absolute urls

This commit is contained in:
Max Peintner
2025-02-28 15:34:34 +01:00
parent 1553b76d74
commit 5a6ae7fb67
7 changed files with 28 additions and 20 deletions

View File

@@ -46,6 +46,8 @@ export default async function Page(props: { searchParams: Promise<any> }) {
const doSend = invite !== "true"; const doSend = invite !== "true";
const basePath = process.env.NEXT_PUBLIC_BASE_PATH ?? "";
if ("loginName" in searchParams) { if ("loginName" in searchParams) {
sessionFactors = await loadMostRecentSession({ sessionFactors = await loadMostRecentSession({
serviceUrl, serviceUrl,
@@ -59,10 +61,9 @@ export default async function Page(props: { searchParams: Promise<any> }) {
if (doSend && sessionFactors?.factors?.user?.id) { if (doSend && sessionFactors?.factors?.user?.id) {
await sendEmailCode({ await sendEmailCode({
serviceUrl, serviceUrl,
userId: sessionFactors?.factors?.user?.id, userId: sessionFactors?.factors?.user?.id,
urlTemplate: urlTemplate:
`${host.includes("localhost") ? "http://" : "https://"}${host}/verify?code={{.Code}}&userId={{.UserID}}&organization={{.OrgID}}&invite=true` + `${host.includes("localhost") ? "http://" : "https://"}${host}${basePath}/verify?code={{.Code}}&userId={{.UserID}}&organization={{.OrgID}}&invite=true` +
(authRequestId ? `&authRequestId=${authRequestId}` : ""), (authRequestId ? `&authRequestId=${authRequestId}` : ""),
}).catch((error) => { }).catch((error) => {
console.error("Could not resend verification email", error); console.error("Could not resend verification email", error);
@@ -73,10 +74,9 @@ export default async function Page(props: { searchParams: Promise<any> }) {
if (doSend) { if (doSend) {
await sendEmailCode({ await sendEmailCode({
serviceUrl, serviceUrl,
userId, userId,
urlTemplate: urlTemplate:
`${host.includes("localhost") ? "http://" : "https://"}${host}/verify?code={{.Code}}&userId={{.UserID}}&organization={{.OrgID}}&invite=true` + `${host.includes("localhost") ? "http://" : "https://"}${host}${basePath}/verify?code={{.Code}}&userId={{.UserID}}&organization={{.OrgID}}&invite=true` +
(authRequestId ? `&authRequestId=${authRequestId}` : ""), (authRequestId ? `&authRequestId=${authRequestId}` : ""),
}).catch((error) => { }).catch((error) => {
console.error("Could not resend verification email", error); console.error("Could not resend verification email", error);

View File

@@ -76,6 +76,8 @@ export function LoginOTP({
async function updateSessionForOTPChallenge() { async function updateSessionForOTPChallenge() {
let challenges; let challenges;
const basePath = process.env.NEXT_PUBLIC_BASE_PATH ?? "";
if (method === "email") { if (method === "email") {
challenges = create(RequestChallengesSchema, { challenges = create(RequestChallengesSchema, {
otpEmail: { otpEmail: {
@@ -84,7 +86,7 @@ export function LoginOTP({
value: host value: host
? { ? {
urlTemplate: urlTemplate:
`${host.includes("localhost") ? "http://" : "https://"}${host}/otp/${method}?code={{.Code}}&userId={{.UserID}}&sessionId={{.SessionID}}` + `${host.includes("localhost") ? "http://" : "https://"}${host}${basePath}/otp/${method}?code={{.Code}}&userId={{.UserID}}&sessionId={{.SessionID}}` +
(authRequestId ? `&authRequestId=${authRequestId}` : ""), (authRequestId ? `&authRequestId=${authRequestId}` : ""),
} }
: {}, : {},

View File

@@ -26,13 +26,14 @@ export async function startIDPFlow(command: StartIDPFlowCommand) {
return { error: "Could not get host" }; return { error: "Could not get host" };
} }
const basePath = process.env.NEXT_PUBLIC_BASE_PATH ?? "";
return startIdentityProviderFlow({ return startIdentityProviderFlow({
serviceUrl, serviceUrl,
idpId: command.idpId, idpId: command.idpId,
urls: { urls: {
successUrl: `${host.includes("localhost") ? "http://" : "https://"}${host}${command.successUrl}`, successUrl: `${host.includes("localhost") ? "http://" : "https://"}${host}${basePath}${command.successUrl}`,
failureUrl: `${host.includes("localhost") ? "http://" : "https://"}${host}${command.failureUrl}`, failureUrl: `${host.includes("localhost") ? "http://" : "https://"}${host}${basePath}${command.failureUrl}`,
}, },
}).then((response) => { }).then((response) => {
if ( if (

View File

@@ -43,10 +43,11 @@ export async function inviteUser(command: InviteUserCommand) {
return { error: "Could not create user" }; return { error: "Could not create user" };
} }
const basePath = process.env.NEXT_PUBLIC_BASE_PATH ?? "";
const codeResponse = await createInviteCode({ const codeResponse = await createInviteCode({
serviceUrl, serviceUrl,
urlTemplate: `${host.includes("localhost") ? "http://" : "https://"}${host}${basePath}/verify?code={{.Code}}&userId={{.UserID}}&organization={{.OrgID}}&invite=true`,
urlTemplate: `${host.includes("localhost") ? "http://" : "https://"}${host}/verify?code={{.Code}}&userId={{.UserID}}&organization={{.OrgID}}&invite=true`,
userId: human.userId, userId: human.userId,
}); });

View File

@@ -104,16 +104,17 @@ export async function sendLoginname(command: SendLoginnameCommand) {
params.set("organization", command.organization); params.set("organization", command.organization);
} }
const basePath = process.env.NEXT_PUBLIC_BASE_PATH ?? "";
const resp = await startIdentityProviderFlow({ const resp = await startIdentityProviderFlow({
serviceUrl, serviceUrl,
idpId: identityProviders[0].id, idpId: identityProviders[0].id,
urls: { urls: {
successUrl: successUrl:
`${host.includes("localhost") ? "http://" : "https://"}${host}/idp/${provider}/success?` + `${host.includes("localhost") ? "http://" : "https://"}${host}${basePath}/idp/${provider}/success?` +
new URLSearchParams(params), new URLSearchParams(params),
failureUrl: failureUrl:
`${host.includes("localhost") ? "http://" : "https://"}${host}/idp/${provider}/failure?` + `${host.includes("localhost") ? "http://" : "https://"}${host}${basePath}/idp/${provider}/failure?` +
new URLSearchParams(params), new URLSearchParams(params),
}, },
}); });
@@ -169,16 +170,17 @@ export async function sendLoginname(command: SendLoginnameCommand) {
params.set("organization", command.organization); params.set("organization", command.organization);
} }
const basePath = process.env.NEXT_PUBLIC_BASE_PATH ?? "";
const resp = await startIdentityProviderFlow({ const resp = await startIdentityProviderFlow({
serviceUrl, serviceUrl,
idpId: idp.id, idpId: idp.id,
urls: { urls: {
successUrl: successUrl:
`${host.includes("localhost") ? "http://" : "https://"}${host}/idp/${provider}/success?` + `${host.includes("localhost") ? "http://" : "https://"}${host}${basePath}/idp/${provider}/success?` +
new URLSearchParams(params), new URLSearchParams(params),
failureUrl: failureUrl:
`${host.includes("localhost") ? "http://" : "https://"}${host}/idp/${provider}/failure?` + `${host.includes("localhost") ? "http://" : "https://"}${host}${basePath}/idp/${provider}/failure?` +
new URLSearchParams(params), new URLSearchParams(params),
}, },
}); });

View File

@@ -70,12 +70,13 @@ export async function resetPassword(command: ResetPasswordCommand) {
} }
const userId = users.result[0].userId; const userId = users.result[0].userId;
const basePath = process.env.NEXT_PUBLIC_BASE_PATH ?? "";
return passwordReset({ return passwordReset({
serviceUrl, serviceUrl,
userId, userId,
urlTemplate: urlTemplate:
`${host.includes("localhost") ? "http://" : "https://"}${host}/password/set?code={{.Code}}&userId={{.UserID}}&organization={{.OrgID}}` + `${host.includes("localhost") ? "http://" : "https://"}${host}${basePath}/password/set?code={{.Code}}&userId={{.UserID}}&organization={{.OrgID}}` +
(command.authRequestId ? `&authRequestId=${command.authRequestId}` : ""), (command.authRequestId ? `&authRequestId=${command.authRequestId}` : ""),
}); });
} }

View File

@@ -260,14 +260,15 @@ export async function resendVerification(command: resendVerifyEmailCommand) {
return { error: "No host found" }; return { error: "No host found" };
} }
const basePath = process.env.NEXT_PUBLIC_BASE_PATH ?? "";
return command.isInvite return command.isInvite
? resendInviteCode({ serviceUrl, userId: command.userId }) ? resendInviteCode({ serviceUrl, userId: command.userId })
: resendEmailCode({ : resendEmailCode({
userId: command.userId, userId: command.userId,
serviceUrl, serviceUrl,
urlTemplate: urlTemplate:
`${host.includes("localhost") ? "http://" : "https://"}${host}/password/set?code={{.Code}}&userId={{.UserID}}&organization={{.OrgID}}` + `${host.includes("localhost") ? "http://" : "https://"}${host}${basePath}/password/set?code={{.Code}}&userId={{.UserID}}&organization={{.OrgID}}` +
(command.authRequestId (command.authRequestId
? `&authRequestId=${command.authRequestId}` ? `&authRequestId=${command.authRequestId}`
: ""), : ""),