mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-23 13:26:41 +00:00
improve verify email redirect flow
This commit is contained in:
@@ -30,7 +30,15 @@ export default function DashboardLoginForm({
|
||||
<CardContent>
|
||||
<LoginForm
|
||||
redirect={redirect}
|
||||
onLogin={() => router.push("/")}
|
||||
onLogin={() => {
|
||||
if (redirect && redirect.includes("http")) {
|
||||
window.location.href = redirect;
|
||||
} else if (redirect) {
|
||||
router.push(redirect);
|
||||
} else {
|
||||
router.push("/");
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -38,6 +38,7 @@ import { LoginResponse } from "@server/routers/auth";
|
||||
import ResourceAccessDenied from "./ResourceAccessDenied";
|
||||
import LoginForm from "@app/components/LoginForm";
|
||||
import { AuthWithPasswordResponse } from "@server/routers/resource";
|
||||
import { redirect } from "next/dist/server/api-utils";
|
||||
|
||||
const pinSchema = z.object({
|
||||
pin: z
|
||||
@@ -113,11 +114,6 @@ export default function ResourceAuthPortal(props: ResourceAuthPortalProps) {
|
||||
},
|
||||
});
|
||||
|
||||
function constructRedirect(redirect: string): string {
|
||||
const redirectUrl = new URL(redirect);
|
||||
return redirectUrl.toString();
|
||||
}
|
||||
|
||||
const onPinSubmit = (values: z.infer<typeof pinSchema>) => {
|
||||
setLoadingLogin(true);
|
||||
api.post<AxiosResponse<AuthWithPasswordResponse>>(
|
||||
@@ -127,9 +123,7 @@ export default function ResourceAuthPortal(props: ResourceAuthPortalProps) {
|
||||
.then((res) => {
|
||||
const session = res.data.data.session;
|
||||
if (session) {
|
||||
const url = constructRedirect(props.redirect);
|
||||
console.log(url);
|
||||
window.location.href = url;
|
||||
window.location.href = props.redirect;
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
@@ -152,7 +146,7 @@ export default function ResourceAuthPortal(props: ResourceAuthPortalProps) {
|
||||
.then((res) => {
|
||||
const session = res.data.data.session;
|
||||
if (session) {
|
||||
window.location.href = constructRedirect(props.redirect);
|
||||
window.location.href = props.redirect;
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
@@ -172,7 +166,7 @@ export default function ResourceAuthPortal(props: ResourceAuthPortalProps) {
|
||||
}
|
||||
|
||||
if (!accessDenied) {
|
||||
window.location.href = constructRedirect(props.redirect);
|
||||
window.location.href = props.redirect;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -371,6 +365,7 @@ export default function ResourceAuthPortal(props: ResourceAuthPortalProps) {
|
||||
className={`${numMethods <= 1 ? "mt-0" : ""}`}
|
||||
>
|
||||
<LoginForm
|
||||
redirect={window.location.href}
|
||||
onLogin={async () =>
|
||||
await handleSSOAuth()
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ export default function VerifyEmailForm({
|
||||
.catch((e) => {
|
||||
setError(formatAxiosError(e, "An error occurred"));
|
||||
console.error("Failed to verify email:", e);
|
||||
setIsSubmitting(false);
|
||||
});
|
||||
|
||||
if (res && res.data?.data?.valid) {
|
||||
@@ -125,7 +126,7 @@ export default function VerifyEmailForm({
|
||||
<div>
|
||||
<Card className="w-full max-w-md">
|
||||
<CardHeader>
|
||||
<CardTitle>Verify Your Email</CardTitle>
|
||||
<CardTitle>Verify Email</CardTitle>
|
||||
<CardDescription>
|
||||
Enter the verification code sent to your email address.
|
||||
</CardDescription>
|
||||
@@ -234,7 +235,7 @@ export default function VerifyEmailForm({
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<div className="text-center text-muted-foreground mt-4">
|
||||
<div className="text-center text-muted-foreground mt-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant="link"
|
||||
|
||||
@@ -8,13 +8,13 @@ export const dynamic = "force-dynamic";
|
||||
export default async function Page(props: {
|
||||
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
|
||||
}) {
|
||||
if (process.env.PUBLIC_FLAGS_EMAIL_VERIFICATION_REQUIRED !== "true") {
|
||||
if (process.env.FLAGS_EMAIL_VERIFICATION_REQUIRED !== "true") {
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
const searchParams = await props.searchParams;
|
||||
const getUser = cache(verifySession);
|
||||
const user = await getUser();
|
||||
const user = await getUser({ skipCheckVerifyEmail: true });
|
||||
|
||||
if (!user) {
|
||||
redirect("/");
|
||||
|
||||
Reference in New Issue
Block a user