diff --git a/src/components/features/auth/sign-in-button.tsx b/src/components/features/auth/sign-in-button.tsx index 6cba4bb..4b4d739 100644 --- a/src/components/features/auth/sign-in-button.tsx +++ b/src/components/features/auth/sign-in-button.tsx @@ -7,9 +7,11 @@ import { Button } from "../../ui/button"; export function SignInButton({ className, + redirectTo = "/", ...props }: React.ComponentProps<"button"> & { className?: string; + redirectTo?: string; }) { const router = useRouter(); @@ -24,13 +26,13 @@ export function SignInButton({ hd: ORGANIZER_EMAIL_DOMAIN, }); await signInWithPopup(auth, provider); + await router.navigate({ + to: getSafeRedirectPath(redirectTo), + }); } catch (error) { console.error("Error signing in with Google:", error); } finally { setLoading(false); - router.navigate({ - to: "/", - }); } }; @@ -65,3 +67,11 @@ export function SignInButton({ ); } + +const getSafeRedirectPath = (redirectTo: string) => { + if (!redirectTo.startsWith("/") || redirectTo.startsWith("//")) { + return "/"; + } + + return redirectTo; +}; diff --git a/src/routes/signin.tsx b/src/routes/signin.tsx index e7d19e7..07e2d30 100644 --- a/src/routes/signin.tsx +++ b/src/routes/signin.tsx @@ -3,11 +3,20 @@ import { NwHacksIcon } from "@/components/graphy/icono"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { createFileRoute } from "@tanstack/react-router"; +type SigninSearch = { + redirect?: string; +}; + export const Route = createFileRoute("/signin")({ + validateSearch: (search: Record): SigninSearch => ({ + redirect: typeof search.redirect === "string" ? search.redirect : undefined, + }), component: Signin, }); function Signin() { + const { redirect } = Route.useSearch(); + return (
Welcome back! - +