mirror of
https://github.com/supabase/supabase.git
synced 2026-09-09 03:19:36 +08:00
Sweeps the example code that creating-a-client.mdx and other auth docs pull via $CodeSample, so the rendered pages match the "use getClaims()" guidance. Also adds Database type stubs and parameterizes SupabaseClient<Database> across SvelteKit and Hono examples. Fixes #40985 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **Documentation** * Updated OAuth server getting-started guide to use a claims-based consent/auth gate and preserve the authorization identifier on redirect. * Added the `auth_methods` partial across framework sections in the server-side “creating a client” guide. * **Refactor** * Updated authentication examples for Hono, Next.js, and SvelteKit to rely on JWT claims for logged-in checks and protected routes. * Streamlined example auth state and UI rendering to use claims-derived information. * **Type Updates** * Improved TypeScript typing for Supabase clients and app auth data across examples, including generated database type stubs. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Chris Chinchilla <chris@chrischinchilla.com>
37 lines
928 B
TypeScript
37 lines
928 B
TypeScript
import { createClient } from '@/lib/supabase/server'
|
|
import Link from 'next/link'
|
|
import { redirect } from 'next/navigation'
|
|
|
|
export default async function AuthButton() {
|
|
const supabase = await createClient()
|
|
|
|
const { data } = await supabase.auth.getClaims()
|
|
const claims = data?.claims
|
|
|
|
const signOut = async () => {
|
|
'use server'
|
|
|
|
const supabase = await createClient()
|
|
await supabase.auth.signOut()
|
|
return redirect('/login')
|
|
}
|
|
|
|
return claims ? (
|
|
<div className="flex items-center gap-4">
|
|
Hey, {claims.email}!
|
|
<form action={signOut}>
|
|
<button className="py-2 px-4 rounded-md no-underline bg-btn-background hover:bg-btn-background-hover">
|
|
Logout
|
|
</button>
|
|
</form>
|
|
</div>
|
|
) : (
|
|
<Link
|
|
href="/login"
|
|
className="py-2 px-3 flex rounded-md no-underline bg-btn-background hover:bg-btn-background-hover"
|
|
>
|
|
Login
|
|
</Link>
|
|
)
|
|
}
|