diff --git a/messages/en-US.json b/messages/en-US.json index 6783e974..ca5557bc 100644 --- a/messages/en-US.json +++ b/messages/en-US.json @@ -1724,5 +1724,6 @@ "authPageUpdated": "Auth page updated successfully", "healthCheckNotAvailable": "Local", "rewritePath": "Rewrite Path", - "rewritePathDescription": "Optionally rewrite the path before forwarding to the target." + "rewritePathDescription": "Optionally rewrite the path before forwarding to the target.", + "continueToApplication": "Continue to application" } diff --git a/src/actions/server.ts b/src/actions/server.ts index e2b2d018..a6ccff8c 100644 --- a/src/actions/server.ts +++ b/src/actions/server.ts @@ -57,9 +57,12 @@ function parseSetCookieString( } if (!options.domain) { - const d = host ? new URL(env.app.dashboardUrl).hostname : undefined; + const d = host + ? host.split(":")[0] // strip port if present + : new URL(env.app.dashboardUrl).hostname; if (d) { options.domain = d; + console.log("Setting cookie domain to:", d); } } @@ -91,7 +94,8 @@ async function makeApiRequest( res = await fetch(url, { method, headers, - body: body ? JSON.stringify(body) : undefined + body: body ? JSON.stringify(body) : undefined, + cache: "no-store" }); } catch (fetchError) { console.error("API request failed:", fetchError); diff --git a/src/app/auth/(private)/org/page.tsx b/src/app/auth/(private)/org/page.tsx index f9d1854e..0cbe101b 100644 --- a/src/app/auth/(private)/org/page.tsx +++ b/src/app/auth/(private)/org/page.tsx @@ -69,6 +69,8 @@ export default async function OrgAuthPage(props: { const t = await getTranslations(); const expectedHost = env.app.dashboardUrl.split("//")[1]; + + let redirectToUrl: string | undefined; let loginPage: LoadLoginPageResponse | undefined; if (host !== expectedHost) { try { @@ -110,7 +112,6 @@ export default async function OrgAuthPage(props: { if (res && res.status === 200) { const newToken = res.data.data.token; - redirectToken = newToken; } } catch (e) { @@ -120,9 +121,8 @@ export default async function OrgAuthPage(props: { } if (redirectToken) { - redirect( - `${env.app.dashboardUrl}/auth/org?token=${redirectToken}` - ); + redirectToUrl = `${env.app.dashboardUrl}/auth/org?token=${redirectToken}`; + redirect(redirectToUrl); } } } else { diff --git a/src/components/private/IdpLoginButtons.tsx b/src/components/private/IdpLoginButtons.tsx index 95e9a9f3..6b3a2e0b 100644 --- a/src/components/private/IdpLoginButtons.tsx +++ b/src/components/private/IdpLoginButtons.tsx @@ -13,13 +13,21 @@ "use client"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { Button } from "@app/components/ui/button"; import { Alert, AlertDescription } from "@app/components/ui/alert"; import { useTranslations } from "next-intl"; import Image from "next/image"; -import { generateOidcUrlProxy, type GenerateOidcUrlResponse } from "@app/actions/server"; -import { redirect as redirectTo } from "next/navigation"; +import { + generateOidcUrlProxy, + type GenerateOidcUrlResponse +} from "@app/actions/server"; +import { + redirect as redirectTo, + useParams, + useSearchParams +} from "next/navigation"; +import { useRouter } from "next/navigation"; export type LoginFormIDP = { idpId: number; @@ -42,6 +50,20 @@ export default function IdpLoginButtons({ const [loading, setLoading] = useState(false); const t = useTranslations(); + const params = useSearchParams(); + const router = useRouter(); + + function goToApp() { + const url = window.location.href.split("?")[0]; + router.push(url); + } + + useEffect(() => { + if (params.get("gotoapp")) { + goToApp(); + } + }, []); + async function loginWithIdp(idpId: number) { setLoading(true); setError(null); @@ -50,7 +72,7 @@ export default function IdpLoginButtons({ try { const response = await generateOidcUrlProxy( idpId, - redirect || "/", + redirect || "/auth/org?gotoapp=app", orgId ); @@ -69,7 +91,8 @@ export default function IdpLoginButtons({ console.error(e); setError( t("loginError", { - defaultValue: "An unexpected error occurred. Please try again." + defaultValue: + "An unexpected error occurred. Please try again." }) ); setLoading(false); @@ -93,42 +116,59 @@ export default function IdpLoginButtons({ )}
- {idps.map((idp) => { - const effectiveType = idp.variant || idp.name.toLowerCase(); - - return ( + {params.get("gotoapp") ? ( + <> - ); - })} + + ) : ( + <> + {idps.map((idp) => { + const effectiveType = + idp.variant || idp.name.toLowerCase(); + + return ( + + ); + })} + + )}
);