mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
### What? [1] Add protected page [2] Add pending state ### Why? [1] People using incorrect ways to protect pages [2] No feedback that the login page is doing anything when buttons clicked ### How? [1] Redirect user to protected page after successful authentication [2] Use useFormStatus to determine whether the form is in a pending state --------- Co-authored-by: Sam Ko <[email protected]>
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import DeployButton from "@/components/DeployButton";
|
|
import AuthButton from "@/components/AuthButton";
|
|
import { createClient } from "@/utils/supabase/server";
|
|
import FetchDataSteps from "@/components/tutorial/FetchDataSteps";
|
|
import Header from "@/components/Header";
|
|
import { redirect } from "next/navigation";
|
|
|
|
export default async function ProtectedPage() {
|
|
const supabase = createClient();
|
|
|
|
const {
|
|
data: { user },
|
|
} = await supabase.auth.getUser();
|
|
|
|
if (!user) {
|
|
return redirect("/login");
|
|
}
|
|
|
|
return (
|
|
<div className="flex-1 w-full flex flex-col gap-20 items-center">
|
|
<div className="w-full">
|
|
<div className="py-6 font-bold bg-purple-950 text-center">
|
|
This is a protected page that you can only see as an authenticated
|
|
user
|
|
</div>
|
|
<nav className="w-full flex justify-center border-b border-b-foreground/10 h-16">
|
|
<div className="w-full max-w-4xl flex justify-between items-center p-3 text-sm">
|
|
<DeployButton />
|
|
<AuthButton />
|
|
</div>
|
|
</nav>
|
|
</div>
|
|
|
|
<div className="animate-in flex-1 flex flex-col gap-20 opacity-0 max-w-4xl px-3">
|
|
<Header />
|
|
<main className="flex-1 flex flex-col gap-6">
|
|
<h2 className="font-bold text-4xl mb-4">Next steps</h2>
|
|
<FetchDataSteps />
|
|
</main>
|
|
</div>
|
|
|
|
<footer className="w-full border-t border-t-foreground/10 p-8 flex justify-center text-center text-xs">
|
|
<p>
|
|
Powered by{" "}
|
|
<a
|
|
href="https://supabase.com/?utm_source=create-next-app&utm_medium=template&utm_term=nextjs"
|
|
target="_blank"
|
|
className="font-bold hover:underline"
|
|
rel="noreferrer"
|
|
>
|
|
Supabase
|
|
</a>
|
|
</p>
|
|
</footer>
|
|
</div>
|
|
);
|
|
}
|