mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
examples: Update with-supabase to be compatible with Nextjs 15 (#71631)
Co-authored-by: Lee Robinson <[email protected]>
This commit is contained in:
co-authored by
Lee Robinson
parent
fe4e4d2c33
commit
703d276ecb
@@ -6,11 +6,10 @@ import { Label } from "@/components/ui/label";
|
||||
import Link from "next/link";
|
||||
import { SmtpMessage } from "../smtp-message";
|
||||
|
||||
export default function ForgotPassword({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Message;
|
||||
export default async function ForgotPassword(props: {
|
||||
searchParams: Promise<Message>;
|
||||
}) {
|
||||
const searchParams = await props.searchParams;
|
||||
return (
|
||||
<>
|
||||
<form className="flex-1 flex flex-col w-full gap-2 text-foreground [&>input]:mb-6 min-w-64 max-w-64 mx-auto">
|
||||
|
||||
@@ -5,7 +5,8 @@ import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import Link from "next/link";
|
||||
|
||||
export default function Login({ searchParams }: { searchParams: Message }) {
|
||||
export default async function Login(props: { searchParams: Promise<Message> }) {
|
||||
const searchParams = await props.searchParams;
|
||||
return (
|
||||
<form className="flex-1 flex flex-col min-w-64">
|
||||
<h1 className="text-2xl font-medium">Sign in</h1>
|
||||
|
||||
@@ -6,7 +6,10 @@ import { Label } from "@/components/ui/label";
|
||||
import Link from "next/link";
|
||||
import { SmtpMessage } from "../smtp-message";
|
||||
|
||||
export default function Signup({ searchParams }: { searchParams: Message }) {
|
||||
export default async function Signup(props: {
|
||||
searchParams: Promise<Message>;
|
||||
}) {
|
||||
const searchParams = await props.searchParams;
|
||||
if ("message" in searchParams) {
|
||||
return (
|
||||
<div className="w-full flex-1 flex items-center h-screen sm:max-w-md justify-center gap-2 p-4">
|
||||
|
||||
@@ -8,8 +8,8 @@ import { redirect } from "next/navigation";
|
||||
export const signUpAction = async (formData: FormData) => {
|
||||
const email = formData.get("email")?.toString();
|
||||
const password = formData.get("password")?.toString();
|
||||
const supabase = createClient();
|
||||
const origin = headers().get("origin");
|
||||
const supabase = await createClient();
|
||||
const origin = (await headers()).get("origin");
|
||||
|
||||
if (!email || !password) {
|
||||
return { error: "Email and password are required" };
|
||||
@@ -38,7 +38,7 @@ export const signUpAction = async (formData: FormData) => {
|
||||
export const signInAction = async (formData: FormData) => {
|
||||
const email = formData.get("email") as string;
|
||||
const password = formData.get("password") as string;
|
||||
const supabase = createClient();
|
||||
const supabase = await createClient();
|
||||
|
||||
const { error } = await supabase.auth.signInWithPassword({
|
||||
email,
|
||||
@@ -54,8 +54,8 @@ export const signInAction = async (formData: FormData) => {
|
||||
|
||||
export const forgotPasswordAction = async (formData: FormData) => {
|
||||
const email = formData.get("email")?.toString();
|
||||
const supabase = createClient();
|
||||
const origin = headers().get("origin");
|
||||
const supabase = await createClient();
|
||||
const origin = (await headers()).get("origin");
|
||||
const callbackUrl = formData.get("callbackUrl")?.toString();
|
||||
|
||||
if (!email) {
|
||||
@@ -87,7 +87,7 @@ export const forgotPasswordAction = async (formData: FormData) => {
|
||||
};
|
||||
|
||||
export const resetPasswordAction = async (formData: FormData) => {
|
||||
const supabase = createClient();
|
||||
const supabase = await createClient();
|
||||
|
||||
const password = formData.get("password") as string;
|
||||
const confirmPassword = formData.get("confirmPassword") as string;
|
||||
@@ -124,7 +124,7 @@ export const resetPasswordAction = async (formData: FormData) => {
|
||||
};
|
||||
|
||||
export const signOutAction = async () => {
|
||||
const supabase = createClient();
|
||||
const supabase = await createClient();
|
||||
await supabase.auth.signOut();
|
||||
return redirect("/sign-in");
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@ export async function GET(request: Request) {
|
||||
const redirectTo = requestUrl.searchParams.get("redirect_to")?.toString();
|
||||
|
||||
if (code) {
|
||||
const supabase = createClient();
|
||||
const supabase = await createClient();
|
||||
await supabase.auth.exchangeCodeForSession(code);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { InfoIcon } from "lucide-react";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default async function ProtectedPage() {
|
||||
const supabase = createClient();
|
||||
const supabase = await createClient();
|
||||
|
||||
const {
|
||||
data: { user },
|
||||
|
||||
@@ -4,11 +4,10 @@ import { SubmitButton } from "@/components/submit-button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
|
||||
export default async function ResetPassword({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Message;
|
||||
export default async function ResetPassword(props: {
|
||||
searchParams: Promise<Message>;
|
||||
}) {
|
||||
const searchParams = await props.searchParams;
|
||||
return (
|
||||
<form className="flex flex-col w-full max-w-md p-4 gap-2 [&>input]:mb-4">
|
||||
<h1 className="text-2xl font-medium">Reset password</h1>
|
||||
|
||||
@@ -6,9 +6,11 @@ import { Button } from "./ui/button";
|
||||
import { createClient } from "@/utils/supabase/server";
|
||||
|
||||
export default async function AuthButton() {
|
||||
const supabase = await createClient();
|
||||
|
||||
const {
|
||||
data: { user },
|
||||
} = await createClient().auth.getUser();
|
||||
} = await supabase.auth.getUser();
|
||||
|
||||
if (!hasEnvVars) {
|
||||
return (
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { createServerClient } from "@supabase/ssr";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
export const createClient = () => {
|
||||
const cookieStore = cookies();
|
||||
export const createClient = async () => {
|
||||
const cookieStore = await cookies();
|
||||
|
||||
return createServerClient(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
|
||||
Reference in New Issue
Block a user