Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

✨ Automatically redirect to oidc configured login (#2044)

Luke Vellad53bb63241a3
diff --git a/apps/web/public/locales/en/app.json b/apps/web/public/locales/en/app.json
index 1de3d6d57..724fa7b15 100644
--- a/apps/web/public/locales/en/app.json
+++ b/apps/web/public/locales/en/app.json
@@ -149,7 +149,6 @@
"expand": "Expand",
"supportDescription": "Need help with anything?",
"contactSupport": "Contact Support",
- "pricing": "Pricing",
"pollSettingsDescription": "Customize the behaviour of your poll",
"requireParticipantEmailLabel": "Make email address required for participants",
"hideParticipantsLabel": "Hide participant list from other participants",
@@ -559,5 +558,6 @@
"resetPasswordButton": "Reset password",
"passwordStrength": "Password Strength",
"emailChangeInvalidUserId": "Please login with the same email address as the one you used to request the change.",
- "ssoAuthenticationOnly": "Authentication is managed through Single Sign-On (SSO). Password management is not available."
+ "ssoAuthenticationOnly": "Authentication is managed through Single Sign-On (SSO). Password management is not available.",
+ "oidcAutoSignInDescription": "You are being redirected to the login page..."
}
diff --git a/apps/web/src/app/[locale]/(auth)/login/components/oidc-auto-sign-in.tsx b/apps/web/src/app/[locale]/(auth)/login/components/oidc-auto-sign-in.tsx
new file mode 100644
index 000000000..f7564d5ea
--- /dev/null
+++ b/apps/web/src/app/[locale]/(auth)/login/components/oidc-auto-sign-in.tsx
@@ -0,0 +1,35 @@
+"use client";
+
+import { useSearchParams } from "next/navigation";
+import useMount from "react-use/lib/useMount";
+import { Spinner } from "@/components/spinner";
+import { Trans } from "@/components/trans";
+import { authClient } from "@/lib/auth-client";
+import { validateRedirectUrl } from "@/utils/redirect";
+
+export function OIDCAutoSignIn() {
+ const searchParams = useSearchParams();
+ const redirectTo = searchParams.get("redirectTo");
+
+ useMount(() => {
+ authClient.signIn.oauth2({
+ providerId: "oidc",
+ callbackURL: validateRedirectUrl(redirectTo) || "/",
+ errorCallbackURL: "/login?error=OAuthSignInFailed",
+ });
+ });
+
+ return (
+ <div className="flex h-dvh items-center justify-center">
+ <div className="flex flex-col items-center gap-2 text-center">
+ <Spinner />
+ <div className="text-muted-foreground text-sm">
+ <Trans
+ i18nKey="oidcAutoSignInDescription"
+ defaults="You are being redirected to the login page..."
+ />
+ </div>
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/src/app/[locale]/(auth)/login/page.tsx b/apps/web/src/app/[locale]/(auth)/login/page.tsx
index 14322b507..00fa794d0 100644
--- a/apps/web/src/app/[locale]/(auth)/login/page.tsx
+++ b/apps/web/src/app/[locale]/(auth)/login/page.tsx
@@ -1,6 +1,7 @@
import type { Metadata } from "next";
import { redirect } from "next/navigation";
import { Trans } from "react-i18next/TransWithoutContext";
+import { OIDCAutoSignIn } from "@/app/[locale]/(auth)/login/components/oidc-auto-sign-in";
import { env } from "@/env";
import { getTranslation } from "@/i18n/server";
import { authLib, getSession } from "@/lib/auth";
@@ -36,6 +37,7 @@ async function loadData() {
export default async function LoginPage(props: {
searchParams?: Promise<{
redirectTo?: string;
+ error?: string;
}>;
}) {
const searchParams = await props.searchParams;
@@ -51,8 +53,21 @@ export default async function LoginPage(props: {
const hasOidc = !!authLib.options.plugins.find(
(plugin) => plugin.id === "generic-oauth",
);
- const hasAlternateLoginMethods =
- hasGoogleProvider || hasMicrosoftProvider || hasOidc;
+
+ const hasSocialLogin = hasGoogleProvider || hasMicrosoftProvider;
+
+ const hasAlternateLoginMethods = hasSocialLogin || hasOidc;
+
+ const hasError = !!searchParams?.error;
+
+ const shouldAutoSignIn =
+ hasOidc && !hasError && !isEmailLoginEnabled && !hasSocialLogin;
+ /**
+ * If there is only one login method available, we should automatically redirect to the login page.
+ */
+ if (shouldAutoSignIn) {
+ return <OIDCAutoSignIn />;
+ }
return (
<AuthPageContainer>