This commit is contained in:
songtianlun 2025-08-30 14:24:41 +08:00
parent f8ce3ee759
commit 570b93b74c
6 changed files with 37 additions and 29 deletions

View File

@ -1,6 +1,7 @@
import { NextRequest, NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
import { createServerSupabaseClient } from '@/lib/supabase-server'
import { auth } from '@/lib/auth'
import { headers } from 'next/headers'
export async function POST(
request: NextRequest,
@ -8,16 +9,17 @@ export async function POST(
) {
const { id } = await params
try {
const supabase = await createServerSupabaseClient()
const { data: { user: supabaseUser }, error: authError } = await supabase.auth.getUser()
if (authError || !supabaseUser) {
const session = await auth.api.getSession({
headers: await headers()
})
if (!session?.user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
// Check if user is admin
const user = await prisma.user.findUnique({
where: { id: supabaseUser.id },
where: { id: session.user.id },
select: { isAdmin: true }
})

View File

@ -1,6 +1,7 @@
import { NextRequest, NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
import { createServerSupabaseClient } from '@/lib/supabase-server'
import { auth } from '@/lib/auth'
import { headers } from 'next/headers'
export async function POST(
request: NextRequest,
@ -8,16 +9,17 @@ export async function POST(
) {
const { id } = await params
try {
const supabase = await createServerSupabaseClient()
const { data: { user: supabaseUser }, error: authError } = await supabase.auth.getUser()
if (authError || !supabaseUser) {
const session = await auth.api.getSession({
headers: await headers()
})
if (!session?.user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
// Check if user is admin
const user = await prisma.user.findUnique({
where: { id: supabaseUser.id },
where: { id: session.user.id },
select: { isAdmin: true }
})

View File

@ -1,19 +1,21 @@
import { NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
import { createServerSupabaseClient } from '@/lib/supabase-server'
import { auth } from '@/lib/auth'
import { headers } from 'next/headers'
export async function GET() {
try {
const supabase = await createServerSupabaseClient()
const { data: { user: supabaseUser }, error: authError } = await supabase.auth.getUser()
if (authError || !supabaseUser) {
const session = await auth.api.getSession({
headers: await headers()
})
if (!session?.user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
// Check if user is admin
const user = await prisma.user.findUnique({
where: { id: supabaseUser.id },
where: { id: session.user.id },
select: { isAdmin: true }
})

View File

@ -1,19 +1,21 @@
import { NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
import { createServerSupabaseClient } from '@/lib/supabase-server'
import { auth } from '@/lib/auth'
import { headers } from 'next/headers'
export async function GET() {
try {
const supabase = await createServerSupabaseClient()
const { data: { user: supabaseUser }, error: authError } = await supabase.auth.getUser()
if (authError || !supabaseUser) {
const session = await auth.api.getSession({
headers: await headers()
})
if (!session?.user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
// Check if user is admin
const user = await prisma.user.findUnique({
where: { id: supabaseUser.id },
where: { id: session.user.id },
select: { isAdmin: true }
})

View File

@ -3,7 +3,7 @@
import { useState } from 'react'
import Link from 'next/link'
import { useTranslations } from 'next-intl'
import { useAuthUser } from '@/hooks/useAuthUser'
import { useBetterAuth } from '@/hooks/useBetterAuth'
import { Button } from '@/components/ui/button'
import { ThemeToggle, MobileThemeToggle } from '@/components/ui/theme-toggle'
import { LanguageToggle, MobileLanguageToggle } from '@/components/ui/language-toggle'
@ -12,7 +12,7 @@ import { Logo } from '@/components/ui/logo'
import { Menu, X } from 'lucide-react'
export function Header() {
const { user, signOut } = useAuthUser()
const { user, signOut } = useBetterAuth()
const t = useTranslations('navigation')
const [mobileMenuOpen, setMobileMenuOpen] = useState(false)

View File

@ -7,7 +7,7 @@ import { Button } from '@/components/ui/button'
import { LegacyAvatar } from '@/components/ui/avatar'
import { ChevronDown, User as UserIcon, LogOut, Settings, CreditCard, Receipt } from 'lucide-react'
import { cn } from '@/lib/utils'
import { useAuthUser } from '@/hooks/useAuthUser'
import { useBetterAuth } from '@/hooks/useBetterAuth'
import { useRouter } from 'next/navigation'
interface UserAvatarDropdownProps {
@ -25,7 +25,7 @@ export function MobileUserMenu({
className
}: UserAvatarDropdownProps) {
const t = useTranslations('navigation')
const { isAdmin } = useAuthUser()
const { isAdmin } = useBetterAuth()
const router = useRouter()
const userName = user.name || user.email?.split('@')[0] || 'User'
@ -129,7 +129,7 @@ export function UserAvatarDropdown({
className
}: UserAvatarDropdownProps) {
const t = useTranslations('navigation')
const { isAdmin } = useAuthUser()
const { isAdmin } = useBetterAuth()
const router = useRouter()
const [isOpen, setIsOpen] = useState(false)