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

This commit is contained in:
Luke Vella 2025-02-03 19:28:13 +07:00 committed by GitHub
parent d4b6879a41
commit c152702820
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 12 deletions

View file

@ -1,24 +1,28 @@
"use client";
import { Button } from "@rallly/ui/button"; import { Button } from "@rallly/ui/button";
import { signIn } from "next-auth/react"; import { signIn } from "next-auth/react";
import { Trans } from "react-i18next/TransWithoutContext";
import { getTranslation } from "@/i18n/server"; import { Trans } from "@/components/trans";
export async function LoginWithOIDC({ name }: { name: string }) {
const { t } = await getTranslation();
export async function LoginWithOIDC({
name,
callbackUrl,
}: {
name: string;
callbackUrl?: string;
}) {
return ( return (
<Button <Button
onClick={() => { onClick={() => {
signIn("oidc"); signIn("oidc", {
callbackUrl,
});
}} }}
variant="link" variant="link"
> >
<Trans <Trans
t={t}
i18nKey="continueWithProvider" i18nKey="continueWithProvider"
ns="app" defaults="Continue with {provider}"
defaultValue="Login with {provider}"
values={{ provider: name }} values={{ provider: name }}
/> />
</Button> </Button>

View file

@ -40,9 +40,11 @@ function SSOImage({ provider }: { provider: string }) {
export function SSOProvider({ export function SSOProvider({
providerId, providerId,
name, name,
callbackUrl,
}: { }: {
providerId: string; providerId: string;
name: string; name: string;
callbackUrl?: string;
}) { }) {
const { t } = useTranslation(); const { t } = useTranslation();
return ( return (
@ -55,7 +57,9 @@ export function SSOProvider({
})} })}
key={providerId} key={providerId}
onClick={() => { onClick={() => {
signIn(providerId); signIn(providerId, {
callbackUrl,
});
}} }}
> >
<SSOImage provider={providerId} /> <SSOImage provider={providerId} />

View file

@ -18,7 +18,13 @@ import { LoginWithOIDC } from "./components/login-with-oidc";
import { OrDivider } from "./components/or-divider"; import { OrDivider } from "./components/or-divider";
import { SSOProvider } from "./components/sso-provider"; 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 { t } = await getTranslation();
const oAuthProviders = getOAuthProviders(); const oAuthProviders = getOAuthProviders();
@ -49,7 +55,12 @@ export default async function LoginPage() {
<AuthPageContent> <AuthPageContent>
<LoginWithEmailForm /> <LoginWithEmailForm />
{hasAlternateLoginMethods ? <OrDivider /> : null} {hasAlternateLoginMethods ? <OrDivider /> : null}
{oidcProvider ? <LoginWithOIDC name={oidcProvider.name} /> : null} {oidcProvider ? (
<LoginWithOIDC
name={oidcProvider.name}
callbackUrl={searchParams?.callbackUrl}
/>
) : null}
{socialProviders ? ( {socialProviders ? (
<div className="grid gap-4"> <div className="grid gap-4">
{socialProviders.map((provider) => ( {socialProviders.map((provider) => (
@ -57,6 +68,7 @@ export default async function LoginPage() {
key={provider.id} key={provider.id}
providerId={provider.id} providerId={provider.id}
name={provider.name} name={provider.name}
callbackUrl={searchParams?.callbackUrl}
/> />
))} ))}
</div> </div>