🐛 Fix login/registration flow (#1688)

This commit is contained in:
Luke Vella 2025-04-24 11:49:24 +01:00 committed by GitHub
parent d6c6cc47d3
commit b100c6274e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 8 deletions

View file

@ -10,7 +10,7 @@ import {
FormMessage,
} from "@rallly/ui/form";
import { Input } from "@rallly/ui/input";
import { useRouter } from "next/navigation";
import { useRouter, useSearchParams } from "next/navigation";
import { useForm } from "react-hook-form";
import type { z } from "zod";
@ -25,6 +25,7 @@ type RegisterNameFormValues = z.infer<typeof registerNameFormSchema>;
export function RegisterNameForm() {
const { t } = useTranslation();
const searchParams = useSearchParams();
const form = useForm<RegisterNameFormValues>({
defaultValues: {
name: "",
@ -43,7 +44,10 @@ export function RegisterNameForm() {
if (res.ok) {
await setToken(res.token);
router.push("/register/verify");
const redirectTo = searchParams.get("redirectTo");
router.push(
`/register/verify${redirectTo ? `?redirectTo=${redirectTo}` : ""}`,
);
} else {
switch (res.reason) {
case "emailNotAllowed":

View file

@ -1,13 +1,17 @@
import { Button } from "@rallly/ui/button";
import Image from "next/image";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { Trans } from "@/components/trans";
import { UserDropdown } from "@/components/user-dropdown";
import { useUser } from "../user-provider";
export function PollHeader() {
const { user } = useUser();
const pathname = usePathname();
const redirectTo = `?redirectTo=${encodeURIComponent(pathname)}`;
return (
<div className="sticky top-0 z-40 border-b bg-gray-100/90 p-3 backdrop-blur-md">
<div className="mx-auto flex max-w-4xl items-center justify-between">
@ -33,10 +37,14 @@ export function PollHeader() {
) : (
<>
<Button variant="ghost" asChild>
<Link href="/login">Login</Link>
<Link href={`/login${redirectTo}`}>
<Trans i18nKey="login" defaults="Login" />
</Link>
</Button>
<Button variant="primary" asChild>
<Link href="/register">Sign Up</Link>
<Link href={`/register${redirectTo}`}>
<Trans i18nKey="signUp" defaults="Sign Up" />
</Link>
</Button>
</>
)}

View file

@ -41,10 +41,6 @@ test.describe.serial(() => {
email: TEST_USER_EMAIL,
});
// Step 4: Navigate back to the poll
await page.getByRole("main").getByRole("link", { name: "Polls" }).click();
await expect(page).toHaveURL(/polls/);
await page.click("text=Monthly Meetup");
await expect(page.getByTestId("poll-title")).toHaveText("Monthly Meetup");
});