mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
chore(docs): update examples for nextjs 15 breaking changes
cookies() is now asynchronous
This commit is contained in:
1 parent
881d8a333b
commit
652c4288e6
15 files changed
+99
-100
No files matched your search
@@ -1,16 +1,16 @@
|
||||
import { type EmailOtpType } from "@supabase/supabase-js"
|
||||
import { type NextRequest, NextResponse } from "next/server"
|
||||
import { createClient } from "@/utils/supabase/server"
|
||||
import { redirect } from "next/navigation"
|
||||
import { type EmailOtpType } from '@supabase/supabase-js'
|
||||
import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { createClient } from '@/utils/supabase/server'
|
||||
import { redirect } from 'next/navigation'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const token_hash = searchParams.get("token_hash")
|
||||
const type = searchParams.get("type") as EmailOtpType | null
|
||||
const next = searchParams.get("next") ?? "/"
|
||||
const token_hash = searchParams.get('token_hash')
|
||||
const type = searchParams.get('type') as EmailOtpType | null
|
||||
const next = searchParams.get('next') ?? '/'
|
||||
|
||||
if (token_hash && type) {
|
||||
const supabase = createClient()
|
||||
const supabase = await createClient()
|
||||
|
||||
const { error } = await supabase.auth.verifyOtp({
|
||||
type,
|
||||
@@ -23,5 +23,5 @@ export async function GET(request: NextRequest) {
|
||||
}
|
||||
|
||||
// redirect the user to an error page with some instructions
|
||||
redirect("/error")
|
||||
redirect('/error')
|
||||
}
|
||||
@@ -1,45 +1,45 @@
|
||||
"use server"
|
||||
'use server'
|
||||
|
||||
import { revalidatePath } from "next/cache"
|
||||
import { redirect } from "next/navigation"
|
||||
import { createClient } from "@/utils/supabase/server"
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { redirect } from 'next/navigation'
|
||||
import { createClient } from '@/utils/supabase/server'
|
||||
|
||||
export async function signIn(formData: FormData) {
|
||||
const supabase = createClient()
|
||||
const supabase = await createClient()
|
||||
|
||||
// type-casting here for convenience
|
||||
// in practice, you should validate your inputs
|
||||
const data = {
|
||||
email: formData.get("email") as string,
|
||||
password: formData.get("password") as string,
|
||||
email: formData.get('email') as string,
|
||||
password: formData.get('password') as string,
|
||||
}
|
||||
|
||||
const { error } = await supabase.auth.signInWithPassword(data)
|
||||
|
||||
if (error) {
|
||||
redirect("/error")
|
||||
redirect('/error')
|
||||
}
|
||||
|
||||
revalidatePath("/", "layout")
|
||||
redirect("/")
|
||||
revalidatePath('/', 'layout')
|
||||
redirect('/')
|
||||
}
|
||||
|
||||
export async function signUp(formData: FormData) {
|
||||
const supabase = createClient()
|
||||
const supabase = await createClient()
|
||||
|
||||
// type-casting here for convenience
|
||||
// in practice, you should validate your inputs
|
||||
const data = {
|
||||
email: formData.get("email") as string,
|
||||
password: formData.get("password") as string,
|
||||
email: formData.get('email') as string,
|
||||
password: formData.get('password') as string,
|
||||
}
|
||||
|
||||
const { error } = await supabase.auth.signUp(data)
|
||||
|
||||
if (error) {
|
||||
redirect("/error")
|
||||
redirect('/error')
|
||||
}
|
||||
|
||||
revalidatePath("/", "layout")
|
||||
redirect("/")
|
||||
revalidatePath('/', 'layout')
|
||||
redirect('/')
|
||||
}
|
||||
@@ -1,27 +1,26 @@
|
||||
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";
|
||||
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 supabase = await createClient()
|
||||
|
||||
const {
|
||||
data: { user },
|
||||
} = await supabase.auth.getUser();
|
||||
} = await supabase.auth.getUser()
|
||||
|
||||
if (!user) {
|
||||
return redirect("/login");
|
||||
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
|
||||
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">
|
||||
@@ -41,7 +40,7 @@ export default async function ProtectedPage() {
|
||||
|
||||
<footer className="w-full border-t border-t-foreground/10 p-8 flex justify-center text-center text-xs">
|
||||
<p>
|
||||
Powered by{" "}
|
||||
Powered by{' '}
|
||||
<a
|
||||
href="https://supabase.com/?utm_source=create-next-app&utm_medium=template&utm_term=nextjs"
|
||||
target="_blank"
|
||||
@@ -53,5 +52,5 @@ export default async function ProtectedPage() {
|
||||
</p>
|
||||
</footer>
|
||||
</div>
|
||||
);
|
||||
)
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
import { createClient } from "@/utils/supabase/server";
|
||||
import Link from "next/link";
|
||||
import { redirect } from "next/navigation";
|
||||
import { createClient } from '@/utils/supabase/server'
|
||||
import Link from 'next/link'
|
||||
import { redirect } from 'next/navigation'
|
||||
|
||||
export default async function AuthButton() {
|
||||
const supabase = createClient();
|
||||
const supabase = await createClient()
|
||||
|
||||
const {
|
||||
data: { user },
|
||||
} = await supabase.auth.getUser();
|
||||
} = await supabase.auth.getUser()
|
||||
|
||||
const signOut = async () => {
|
||||
"use server";
|
||||
'use server'
|
||||
|
||||
const supabase = createClient();
|
||||
await supabase.auth.signOut();
|
||||
return redirect("/login");
|
||||
};
|
||||
const supabase = createClient()
|
||||
await supabase.auth.signOut()
|
||||
return redirect('/login')
|
||||
}
|
||||
|
||||
return user ? (
|
||||
<div className="flex items-center gap-4">
|
||||
@@ -33,5 +33,5 @@ export default async function AuthButton() {
|
||||
>
|
||||
Login
|
||||
</Link>
|
||||
);
|
||||
)
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import { createServerClient, type CookieOptions } from "@supabase/ssr"
|
||||
import { cookies } from "next/headers"
|
||||
import { createServerClient } from '@supabase/ssr'
|
||||
import { cookies } from 'next/headers'
|
||||
|
||||
export function createClient() {
|
||||
const cookieStore = cookies()
|
||||
export async function createClient() {
|
||||
const cookieStore = await cookies()
|
||||
|
||||
return createServerClient(
|
||||
process.env.NEXT_PUBLIC_SUPABASE_URL!,
|
||||
|
||||
Reference in new issue
Block a user