mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-05 18:44:40 +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 { verifySession } from "@app/lib/auth/verifySession";
|
||||||
import { redirect } from "next/navigation";
|
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();
|
const user = await verifySession();
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
|
@ -11,7 +15,7 @@ export default async function Page() {
|
||||||
|
|
||||||
return (
|
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 { verifySession } from "@app/lib/auth/verifySession";
|
||||||
import { redirect } from "next/navigation";
|
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();
|
const user = await verifySession();
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
|
@ -13,11 +17,12 @@ export default async function Page() {
|
||||||
redirect("/");
|
redirect("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(user.email)
|
|
||||||
|
|
||||||
return (
|
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);
|
setError(null);
|
||||||
|
|
||||||
if (res.data?.data?.emailVerificationRequired) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (redirect && typeof redirect === "string") {
|
if (redirect && redirect.includes("http")) {
|
||||||
window.location.href = redirect;
|
window.location.href = redirect;
|
||||||
|
} else if (redirect) {
|
||||||
|
router.push(redirect);
|
||||||
} else {
|
} else {
|
||||||
router.push("/");
|
router.push("/");
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,16 +75,22 @@ export default function SignupForm({ redirect }: SignupFormProps) {
|
||||||
if (res && res.status === 200) {
|
if (res && res.status === 200) {
|
||||||
setError(null);
|
setError(null);
|
||||||
|
|
||||||
if (res.data.data.emailVerificationRequired) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (redirect && typeof redirect === "string") {
|
if (redirect && redirect.includes("http")) {
|
||||||
window.location.href = redirect;
|
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 = {
|
export type VerifyEmailFormProps = {
|
||||||
email: string;
|
email: string;
|
||||||
|
redirect?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function VerifyEmailForm({ email }: VerifyEmailFormProps) {
|
export default function VerifyEmailForm({
|
||||||
|
email,
|
||||||
|
redirect,
|
||||||
|
}: VerifyEmailFormProps) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
@ -82,7 +86,14 @@ export default function VerifyEmailForm({ email }: VerifyEmailFormProps) {
|
||||||
"Email successfully verified! Redirecting you...",
|
"Email successfully verified! Redirecting you...",
|
||||||
);
|
);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
router.push("/");
|
if (redirect && redirect.includes("http")) {
|
||||||
|
window.location.href = redirect;
|
||||||
|
}
|
||||||
|
if (redirect) {
|
||||||
|
router.push(redirect);
|
||||||
|
} else {
|
||||||
|
router.push("/");
|
||||||
|
}
|
||||||
setIsSubmitting(false);
|
setIsSubmitting(false);
|
||||||
}, 3000);
|
}, 3000);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue