fix build
This commit is contained in:
parent
012d8756d8
commit
4180300ab1
@ -97,9 +97,7 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
|
|||||||
// 模拟 AI API 调用
|
// 模拟 AI API 调用
|
||||||
async function runAITest({
|
async function runAITest({
|
||||||
content,
|
content,
|
||||||
model,
|
model
|
||||||
temperature: _temperature,
|
|
||||||
maxTokens: _maxTokens
|
|
||||||
}: {
|
}: {
|
||||||
content: string
|
content: string
|
||||||
model: string
|
model: string
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { prisma } from '@/lib/prisma'
|
|||||||
import { createServerSupabaseClient } from '@/lib/supabase-server'
|
import { createServerSupabaseClient } from '@/lib/supabase-server'
|
||||||
|
|
||||||
// POST /api/users/sync - 同步Supabase用户到Prisma数据库
|
// POST /api/users/sync - 同步Supabase用户到Prisma数据库
|
||||||
export async function POST(request: NextRequest) {
|
export async function POST(_request: NextRequest) {
|
||||||
try {
|
try {
|
||||||
const supabase = await createServerSupabaseClient()
|
const supabase = await createServerSupabaseClient()
|
||||||
const { data: { user: supabaseUser }, error: authError } = await supabase.auth.getUser()
|
const { data: { user: supabaseUser }, error: authError } = await supabase.auth.getUser()
|
||||||
@ -64,7 +64,7 @@ export async function POST(request: NextRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GET /api/users/sync - 获取当前用户信息
|
// GET /api/users/sync - 获取当前用户信息
|
||||||
export async function GET(request: NextRequest) {
|
export async function GET(_request: NextRequest) {
|
||||||
try {
|
try {
|
||||||
const supabase = await createServerSupabaseClient()
|
const supabase = await createServerSupabaseClient()
|
||||||
const { data: { user: supabaseUser }, error: authError } = await supabase.auth.getUser()
|
const { data: { user: supabaseUser }, error: authError } = await supabase.auth.getUser()
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useState, useEffect } from 'react'
|
import { useState, useEffect, useCallback } from 'react'
|
||||||
import { useTranslations } from 'next-intl'
|
import { useTranslations } from 'next-intl'
|
||||||
import { useAuth } from '@/hooks/useAuth'
|
import { useAuth } from '@/hooks/useAuth'
|
||||||
import { createClient } from '@/lib/supabase'
|
import { createClient } from '@/lib/supabase'
|
||||||
@ -57,46 +57,45 @@ export default function ProfilePage() {
|
|||||||
|
|
||||||
const supabase = createClient()
|
const supabase = createClient()
|
||||||
|
|
||||||
|
const loadProfile = useCallback(async () => {
|
||||||
|
setProfileLoading(true)
|
||||||
|
try {
|
||||||
|
// Get user metadata and profile data
|
||||||
|
const { data: { user: userData }, error: userError } = await supabase.auth.getUser()
|
||||||
|
|
||||||
|
if (userError) throw userError
|
||||||
|
|
||||||
|
const profileData: UserProfile = {
|
||||||
|
id: userData?.id || '',
|
||||||
|
email: userData?.email || '',
|
||||||
|
username: userData?.user_metadata?.username || userData?.user_metadata?.full_name || '',
|
||||||
|
bio: userData?.user_metadata?.bio || '',
|
||||||
|
avatar_url: userData?.user_metadata?.avatar_url || '',
|
||||||
|
language: userData?.user_metadata?.language || 'en'
|
||||||
|
}
|
||||||
|
|
||||||
|
setProfile(profileData)
|
||||||
|
setFormData({
|
||||||
|
username: profileData.username || '',
|
||||||
|
email: profileData.email,
|
||||||
|
bio: profileData.bio || '',
|
||||||
|
currentPassword: '',
|
||||||
|
newPassword: '',
|
||||||
|
confirmPassword: '',
|
||||||
|
language: profileData.language || 'en'
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error loading profile:', error)
|
||||||
|
setSaveStatus({ type: 'error', message: t('failedToLoadProfile') })
|
||||||
|
} finally {
|
||||||
|
setProfileLoading(false)
|
||||||
|
}
|
||||||
|
}, [supabase, t])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!user) return
|
if (!user) return
|
||||||
|
|
||||||
const loadProfile = async () => {
|
|
||||||
setProfileLoading(true)
|
|
||||||
try {
|
|
||||||
// Get user metadata and profile data
|
|
||||||
const { data: { user: userData }, error: userError } = await supabase.auth.getUser()
|
|
||||||
|
|
||||||
if (userError) throw userError
|
|
||||||
|
|
||||||
const profileData: UserProfile = {
|
|
||||||
id: userData?.id || '',
|
|
||||||
email: userData?.email || '',
|
|
||||||
username: userData?.user_metadata?.username || userData?.user_metadata?.full_name || '',
|
|
||||||
bio: userData?.user_metadata?.bio || '',
|
|
||||||
avatar_url: userData?.user_metadata?.avatar_url || '',
|
|
||||||
language: userData?.user_metadata?.language || 'en'
|
|
||||||
}
|
|
||||||
|
|
||||||
setProfile(profileData)
|
|
||||||
setFormData({
|
|
||||||
username: profileData.username || '',
|
|
||||||
email: profileData.email,
|
|
||||||
bio: profileData.bio || '',
|
|
||||||
currentPassword: '',
|
|
||||||
newPassword: '',
|
|
||||||
confirmPassword: '',
|
|
||||||
language: profileData.language || 'en'
|
|
||||||
})
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error loading profile:', error)
|
|
||||||
setSaveStatus({ type: 'error', message: t('failedToLoadProfile') })
|
|
||||||
} finally {
|
|
||||||
setProfileLoading(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
loadProfile()
|
loadProfile()
|
||||||
}, [user, supabase, t])
|
}, [user, loadProfile])
|
||||||
|
|
||||||
const updateProfile = async (field: string, value: string) => {
|
const updateProfile = async (field: string, value: string) => {
|
||||||
if (!user) return
|
if (!user) return
|
||||||
|
|||||||
@ -81,7 +81,7 @@ export default function PromptPage({ params }: PromptPageProps) {
|
|||||||
const processedData = {
|
const processedData = {
|
||||||
...data,
|
...data,
|
||||||
tags: Array.isArray(data.tags)
|
tags: Array.isArray(data.tags)
|
||||||
? data.tags.map((tag: any) => typeof tag === 'string' ? tag : tag.name || '')
|
? data.tags.map((tag: string | { name: string }) => typeof tag === 'string' ? tag : tag.name || '')
|
||||||
: []
|
: []
|
||||||
}
|
}
|
||||||
setPrompt(processedData)
|
setPrompt(processedData)
|
||||||
@ -273,8 +273,8 @@ export default function PromptPage({ params }: PromptPageProps) {
|
|||||||
<p className="text-xs text-muted-foreground mt-1 line-clamp-2">{prompt?.description || ''}</p>
|
<p className="text-xs text-muted-foreground mt-1 line-clamp-2">{prompt?.description || ''}</p>
|
||||||
<div className="flex items-center mt-2 space-x-2">
|
<div className="flex items-center mt-2 space-x-2">
|
||||||
{prompt?.tags?.slice(0, 1).map((tag) => (
|
{prompt?.tags?.slice(0, 1).map((tag) => (
|
||||||
<span key={typeof tag === 'string' ? tag : (tag as any)?.name || ''} className="inline-flex items-center px-1.5 py-0.5 text-xs font-medium bg-primary/10 text-primary rounded">
|
<span key={typeof tag === 'string' ? tag : (tag as { name: string })?.name || ''} className="inline-flex items-center px-1.5 py-0.5 text-xs font-medium bg-primary/10 text-primary rounded">
|
||||||
{typeof tag === 'string' ? tag : (tag as any)?.name || ''}
|
{typeof tag === 'string' ? tag : (tag as { name: string })?.name || ''}
|
||||||
</span>
|
</span>
|
||||||
))}
|
))}
|
||||||
{prompt?.tags && prompt.tags.length > 1 && (
|
{prompt?.tags && prompt.tags.length > 1 && (
|
||||||
@ -349,7 +349,7 @@ export default function PromptPage({ params }: PromptPageProps) {
|
|||||||
</div>
|
</div>
|
||||||
<div className="pt-2 border-t border-border">
|
<div className="pt-2 border-t border-border">
|
||||||
<div className="flex flex-wrap gap-1">
|
<div className="flex flex-wrap gap-1">
|
||||||
{prompt?.tags?.map((tag: any) => {
|
{prompt?.tags?.map((tag: string | { name: string }) => {
|
||||||
const tagName = typeof tag === 'string' ? tag : tag?.name || '';
|
const tagName = typeof tag === 'string' ? tag : tag?.name || '';
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
|
|||||||
@ -55,7 +55,7 @@ export function EditPromptModal({
|
|||||||
setDescription(prompt.description || '')
|
setDescription(prompt.description || '')
|
||||||
// 确保tags是字符串数组
|
// 确保tags是字符串数组
|
||||||
const processedTags = Array.isArray(prompt.tags)
|
const processedTags = Array.isArray(prompt.tags)
|
||||||
? prompt.tags.map((tag: any) => typeof tag === 'string' ? tag : tag.name || '')
|
? prompt.tags.map((tag: string | { name: string }) => typeof tag === 'string' ? tag : tag.name || '')
|
||||||
: []
|
: []
|
||||||
setTags(processedTags)
|
setTags(processedTags)
|
||||||
fetchAvailableTags()
|
fetchAvailableTags()
|
||||||
|
|||||||
@ -11,7 +11,7 @@ export function useAuth() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// 同步用户到Prisma数据库
|
// 同步用户到Prisma数据库
|
||||||
const syncUser = async (_userData: User) => {
|
const syncUser = async () => {
|
||||||
try {
|
try {
|
||||||
await fetch('/api/users/sync', {
|
await fetch('/api/users/sync', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -25,7 +25,7 @@ export function useAuth() {
|
|||||||
const getUser = async () => {
|
const getUser = async () => {
|
||||||
const { data: { user: userData } } = await supabase.auth.getUser()
|
const { data: { user: userData } } = await supabase.auth.getUser()
|
||||||
if (userData) {
|
if (userData) {
|
||||||
await syncUser(userData)
|
await syncUser()
|
||||||
}
|
}
|
||||||
setUser(userData)
|
setUser(userData)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
@ -36,7 +36,7 @@ export function useAuth() {
|
|||||||
const { data: { subscription } } = supabase.auth.onAuthStateChange(async (event, session) => {
|
const { data: { subscription } } = supabase.auth.onAuthStateChange(async (event, session) => {
|
||||||
const userData = session?.user ?? null
|
const userData = session?.user ?? null
|
||||||
if (userData && (event === 'SIGNED_IN' || event === 'TOKEN_REFRESHED')) {
|
if (userData && (event === 'SIGNED_IN' || event === 'TOKEN_REFRESHED')) {
|
||||||
await syncUser(userData)
|
await syncUser()
|
||||||
}
|
}
|
||||||
setUser(userData)
|
setUser(userData)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user