File tree Expand file tree Collapse file tree 6 files changed +305
-67
lines changed
components/layout/settings/apikeys Expand file tree Collapse file tree 6 files changed +305
-67
lines changed Original file line number Diff line number Diff line change 1
1
import {
2
2
getAllModels ,
3
- getAllOpenRouterModels ,
3
+ getModelsForUserProviders ,
4
4
getModelsWithAccessFlags ,
5
5
refreshModelsCache ,
6
6
} from "@/lib/models"
@@ -53,10 +53,10 @@ export async function GET() {
53
53
} )
54
54
}
55
55
56
- const hasOpenRouterKey = data ?. some ( ( k ) => k . provider === "openrouter" )
56
+ const userProviders = data ?. map ( ( k ) => k . provider ) || [ ]
57
57
58
- if ( hasOpenRouterKey ) {
59
- const models = await getAllOpenRouterModels ( )
58
+ if ( userProviders . length === 0 ) {
59
+ const models = await getModelsWithAccessFlags ( )
60
60
return new Response ( JSON . stringify ( { models } ) , {
61
61
status : 200 ,
62
62
headers : {
@@ -65,7 +65,7 @@ export async function GET() {
65
65
} )
66
66
}
67
67
68
- const models = await getModelsWithAccessFlags ( )
68
+ const models = await getModelsForUserProviders ( userProviders )
69
69
70
70
return new Response ( JSON . stringify ( { models } ) , {
71
71
status : 200 ,
@@ -86,7 +86,6 @@ export async function GET() {
86
86
87
87
export async function POST ( ) {
88
88
try {
89
- // Refresh the models cache
90
89
refreshModelsCache ( )
91
90
const models = await getAllModels ( )
92
91
Original file line number Diff line number Diff line change 1
1
import { createClient } from "@/lib/supabase/server"
2
2
import { NextResponse } from "next/server"
3
3
4
+ // Supported providers
5
+ const SUPPORTED_PROVIDERS = [ "openrouter" , "openai" ]
6
+
4
7
export async function GET ( ) {
5
8
try {
6
9
const supabase = await createClient ( )
@@ -26,9 +29,17 @@ export async function GET() {
26
29
return NextResponse . json ( { error : error . message } , { status : 500 } )
27
30
}
28
31
29
- const hasOpenRouterKey = data ?. some ( ( k ) => k . provider === "openrouter" )
32
+ // Create status object for all supported providers
33
+ const userProviders = data ?. map ( ( k ) => k . provider ) || [ ]
34
+ const providerStatus = SUPPORTED_PROVIDERS . reduce (
35
+ ( acc , provider ) => {
36
+ acc [ provider ] = userProviders . includes ( provider )
37
+ return acc
38
+ } ,
39
+ { } as Record < string , boolean >
40
+ )
30
41
31
- return NextResponse . json ( { openrouter : hasOpenRouterKey } )
42
+ return NextResponse . json ( providerStatus )
32
43
} catch ( err ) {
33
44
console . error ( "Key status error:" , err )
34
45
return NextResponse . json (
Original file line number Diff line number Diff line change @@ -49,3 +49,47 @@ export async function POST(request: Request) {
49
49
)
50
50
}
51
51
}
52
+
53
+ export async function DELETE ( request : Request ) {
54
+ try {
55
+ const { provider } = await request . json ( )
56
+
57
+ if ( ! provider ) {
58
+ return NextResponse . json (
59
+ { error : "Provider is required" } ,
60
+ { status : 400 }
61
+ )
62
+ }
63
+
64
+ const supabase = await createClient ( )
65
+ if ( ! supabase ) {
66
+ return NextResponse . json (
67
+ { error : "Supabase not available" } ,
68
+ { status : 500 }
69
+ )
70
+ }
71
+
72
+ const { data : authData } = await supabase . auth . getUser ( )
73
+ if ( ! authData ?. user ?. id ) {
74
+ return NextResponse . json ( { error : "Unauthorized" } , { status : 401 } )
75
+ }
76
+
77
+ const { error } = await supabase
78
+ . from ( "user_keys" )
79
+ . delete ( )
80
+ . eq ( "user_id" , authData . user . id )
81
+ . eq ( "provider" , provider )
82
+
83
+ if ( error ) {
84
+ return NextResponse . json ( { error : error . message } , { status : 500 } )
85
+ }
86
+
87
+ return NextResponse . json ( { success : true } )
88
+ } catch ( error ) {
89
+ console . error ( "Error in DELETE /api/user-keys:" , error )
90
+ return NextResponse . json (
91
+ { error : "Internal server error" } ,
92
+ { status : 500 }
93
+ )
94
+ }
95
+ }
You can’t perform that action at this time.
0 commit comments