mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-02 17:14:55 +02:00
add redirect support to signup and verify email
This commit is contained in:
parent
7bfa17a293
commit
f14fb90ab6
5 changed files with 47 additions and 15 deletions
|
@ -2,7 +2,11 @@ import SignupForm from "@app/components/auth/SignupForm";
|
|||
import { verifySession } from "@app/lib/auth/verifySession";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default async function Page() {
|
||||
export default async function Page({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: { [key: string]: string | string[] | undefined };
|
||||
}) {
|
||||
const user = await verifySession();
|
||||
|
||||
if (user) {
|
||||
|
@ -11,7 +15,7 @@ export default async function Page() {
|
|||
|
||||
return (
|
||||
<>
|
||||
<SignupForm />
|
||||
<SignupForm redirect={searchParams.redirect as string} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,11 @@ import VerifyEmailForm from "@app/components/auth/VerifyEmailForm";
|
|||
import { verifySession } from "@app/lib/auth/verifySession";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default async function Page() {
|
||||
export default async function Page({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: { [key: string]: string | string[] | undefined };
|
||||
}) {
|
||||
const user = await verifySession();
|
||||
|
||||
if (!user) {
|
||||
|
@ -13,11 +17,12 @@ export default async function Page() {
|
|||
redirect("/");
|
||||
}
|
||||
|
||||
console.log(user.email)
|
||||
|
||||
return (
|
||||
<>
|
||||
<VerifyEmailForm email={user.email}/>
|
||||
<VerifyEmailForm
|
||||
email={user.email}
|
||||
redirect={searchParams.redirect as string}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -70,12 +70,18 @@ export default function LoginForm({ redirect }: LoginFormProps) {
|
|||
setError(null);
|
||||
|
||||
if (res.data?.data?.emailVerificationRequired) {
|
||||
router.push("/auth/verify-email");
|
||||
if (redirect) {
|
||||
router.push(`/auth/verify-email?redirect=${redirect}`);
|
||||
} else {
|
||||
router.push("/auth/verify-email");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (redirect && typeof redirect === "string") {
|
||||
if (redirect && redirect.includes("http")) {
|
||||
window.location.href = redirect;
|
||||
} else if (redirect) {
|
||||
router.push(redirect);
|
||||
} else {
|
||||
router.push("/");
|
||||
}
|
||||
|
|
|
@ -75,16 +75,22 @@ export default function SignupForm({ redirect }: SignupFormProps) {
|
|||
if (res && res.status === 200) {
|
||||
setError(null);
|
||||
|
||||
if (res.data.data.emailVerificationRequired) {
|
||||
router.push("/auth/verify-email");
|
||||
if (res.data?.data?.emailVerificationRequired) {
|
||||
if (redirect) {
|
||||
router.push(`/auth/verify-email?redirect=${redirect}`);
|
||||
} else {
|
||||
router.push("/auth/verify-email");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (redirect && typeof redirect === "string") {
|
||||
if (redirect && redirect.includes("http")) {
|
||||
window.location.href = redirect;
|
||||
} else if (redirect) {
|
||||
router.push(redirect);
|
||||
} else {
|
||||
router.push("/");
|
||||
}
|
||||
|
||||
router.push("/");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,9 +44,13 @@ const FormSchema = z.object({
|
|||
|
||||
export type VerifyEmailFormProps = {
|
||||
email: string;
|
||||
redirect?: string;
|
||||
};
|
||||
|
||||
export default function VerifyEmailForm({ email }: VerifyEmailFormProps) {
|
||||
export default function VerifyEmailForm({
|
||||
email,
|
||||
redirect,
|
||||
}: VerifyEmailFormProps) {
|
||||
const router = useRouter();
|
||||
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
@ -82,7 +86,14 @@ export default function VerifyEmailForm({ email }: VerifyEmailFormProps) {
|
|||
"Email successfully verified! Redirecting you...",
|
||||
);
|
||||
setTimeout(() => {
|
||||
router.push("/");
|
||||
if (redirect && redirect.includes("http")) {
|
||||
window.location.href = redirect;
|
||||
}
|
||||
if (redirect) {
|
||||
router.push(redirect);
|
||||
} else {
|
||||
router.push("/");
|
||||
}
|
||||
setIsSubmitting(false);
|
||||
}, 3000);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue