Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Forward callback url when signing in with sso provider #1543

Merged
merged 2 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
"use client";
import { Button } from "@rallly/ui/button";
import { signIn } from "next-auth/react";
import { Trans } from "react-i18next/TransWithoutContext";

import { getTranslation } from "@/i18n/server";

export async function LoginWithOIDC({ name }: { name: string }) {
const { t } = await getTranslation();
import { Trans } from "@/components/trans";

export async function LoginWithOIDC({
name,
callbackUrl,
}: {
name: string;
callbackUrl?: string;
}) {
return (
<Button
onClick={() => {
signIn("oidc");
signIn("oidc", {
callbackUrl,
});
}}
variant="link"
>
<Trans
t={t}
i18nKey="continueWithProvider"
ns="app"
defaultValue="Login with {provider}"
defaults="Continue with {provider}"
values={{ provider: name }}
/>
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ function SSOImage({ provider }: { provider: string }) {
export function SSOProvider({
providerId,
name,
callbackUrl,
}: {
providerId: string;
name: string;
callbackUrl?: string;
}) {
const { t } = useTranslation();
return (
Expand All @@ -55,7 +57,9 @@ export function SSOProvider({
})}
key={providerId}
onClick={() => {
signIn(providerId);
signIn(providerId, {
callbackUrl,
});
}}
>
<SSOImage provider={providerId} />
Expand Down
16 changes: 14 additions & 2 deletions apps/web/src/app/[locale]/(auth)/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ import { LoginWithOIDC } from "./components/login-with-oidc";
import { OrDivider } from "./components/or-divider";
import { SSOProvider } from "./components/sso-provider";

export default async function LoginPage() {
export default async function LoginPage({
searchParams,
}: {
searchParams?: {
callbackUrl?: string;
};
}) {
const { t } = await getTranslation();
const oAuthProviders = getOAuthProviders();

Expand Down Expand Up @@ -49,14 +55,20 @@ export default async function LoginPage() {
<AuthPageContent>
<LoginWithEmailForm />
{hasAlternateLoginMethods ? <OrDivider /> : null}
{oidcProvider ? <LoginWithOIDC name={oidcProvider.name} /> : null}
{oidcProvider ? (
<LoginWithOIDC
name={oidcProvider.name}
callbackUrl={searchParams?.callbackUrl}
/>
) : null}
{socialProviders ? (
<div className="grid gap-4">
{socialProviders.map((provider) => (
<SSOProvider
key={provider.id}
providerId={provider.id}
name={provider.name}
callbackUrl={searchParams?.callbackUrl}
/>
))}
</div>
Expand Down
Loading