mirror of
https://github.com/lukevella/rallly.git
synced 2025-04-28 17:56:37 +02:00
🐛 Fix login/registration flow (#1688)
This commit is contained in:
parent
d6c6cc47d3
commit
b100c6274e
3 changed files with 16 additions and 8 deletions
|
@ -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":
|
||||
|
|
|
@ -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>
|
||||
</>
|
||||
)}
|
||||
|
|
|
@ -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");
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue