feat: protege rota de sucesso exigindo parametro na url do stripe
This commit is contained in:
parent
deee744dd1
commit
4037afcac4
1 changed files with 24 additions and 0 deletions
|
|
@ -1,7 +1,31 @@
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { useSearchParams, useNavigate } from "react-router-dom";
|
||||||
import { CheckCircle, Mail, LayoutDashboard, Sparkles } from "lucide-react";
|
import { CheckCircle, Mail, LayoutDashboard, Sparkles } from "lucide-react";
|
||||||
import Footer from "../components/Footer";
|
import Footer from "../components/Footer";
|
||||||
|
|
||||||
export default function SuccessPage() {
|
export default function SuccessPage() {
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const [isValid, setIsValid] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// O Stripe passa 'session_id' automaticamente quando redireciona,
|
||||||
|
// Ou podemos checar um parâmetro manual como '?status=approved'
|
||||||
|
const sessionId = searchParams.get("session_id");
|
||||||
|
const status = searchParams.get("status");
|
||||||
|
|
||||||
|
if (sessionId || status === "approved") {
|
||||||
|
setIsValid(true);
|
||||||
|
} else {
|
||||||
|
// Se não tiver nenhum parâmetro válido, joga de volta pra home
|
||||||
|
navigate("/", { replace: true });
|
||||||
|
}
|
||||||
|
}, [searchParams, navigate]);
|
||||||
|
|
||||||
|
if (!isValid) {
|
||||||
|
return null; // Retorna nulo enquanto valida para não piscar a tela
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-pink-50 text-indigo-900 selection:bg-pink-300 font-sans flex flex-col">
|
<div className="min-h-screen bg-pink-50 text-indigo-900 selection:bg-pink-300 font-sans flex flex-col">
|
||||||
<main className="flex-1 py-12 px-4 md:px-6 flex items-center justify-center">
|
<main className="flex-1 py-12 px-4 md:px-6 flex items-center justify-center">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue