Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion app/api/wakatime/sync/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,24 @@ export async function GET(request: Request) {
}

if (apiKey) {
await supabase
const { error } = await supabase
.from("profiles")
.update({ wakatime_api_key: apiKey })
.eq("id", user.id);

if (error) {
if (error.code === "23505") {
return NextResponse.json(
{ error: "This WakaTime API key is already in use." },
{ status: 400 },
);
}

return NextResponse.json(
{ error: "Failed to update API key" },
{ status: 500 },
);
}
}

const { data: statsResult, error: statsError } = await supabase
Expand Down
2 changes: 1 addition & 1 deletion sql/public.profiles.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
create table public.profiles (
id uuid primary key references auth.users(id) on delete cascade,
email text not null,
wakatime_api_key text,
wakatime_api_key text default null unique,
created_at timestamp with time zone default now()
);

Expand Down
Loading