Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Anchel123 committed Jan 8, 2025
1 parent 4dc2350 commit 5e7c0d2
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 10 deletions.
4 changes: 1 addition & 3 deletions app/api/graph/[graph]/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { NextRequest, NextResponse } from "next/server";
import { getClient } from "@/app/api/auth/[...nextauth]/options";
import { prepareArg, securedFetch } from "@/lib/utils";
import { useToast } from "@/components/ui/use-toast";

// eslint-disable-next-line import/prefer-default-export
export async function DELETE(request: NextRequest, { params }: { params: Promise<{ graph: string }> }) {
Expand Down Expand Up @@ -30,7 +29,6 @@ export async function DELETE(request: NextRequest, { params }: { params: Promise
// eslint-disable-next-line import/prefer-default-export
export async function POST(request: NextRequest, { params }: { params: Promise<{ graph: string }> }) {

const toast = useToast()
const client = await getClient()
if (client instanceof NextResponse) {
return client
Expand Down Expand Up @@ -76,7 +74,7 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
}, toast)
})

const result = await res.json()

Expand Down
14 changes: 8 additions & 6 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ export function cn(...inputs: ClassValue[]) {
export async function securedFetch(
input: string | URL | globalThis.Request,
init: RequestInit,
toast: any,
toast?: any,
): Promise<Response> {
const response = await fetch(input, init)
const { status } = response

if (status >= 300) {
response.json().then((err) => {
toast({
title: "Error",
description: err.message,
variant: "destructive"
})
if (toast) {
toast({
title: "Error",
description: err.message,
variant: "destructive"
})
}
}).then(() => {
if (status === 401 || status >= 500) {
signOut({ callbackUrl: '/login' })
Expand Down
84 changes: 84 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
"@radix-ui/react-dropdown-menu": "^2.1.4",
"@radix-ui/react-hover-card": "^1.1.4",
"@radix-ui/react-label": "^2.1.1",
"@radix-ui/react-navigation-menu": "^1.2.3",
"@radix-ui/react-popover": "^1.1.4",
"@radix-ui/react-progress": "^1.1.1",
"@radix-ui/react-select": "^2.1.4",
"@radix-ui/react-separator": "^1.1.1",
"@radix-ui/react-slot": "^1.1.1",
"@radix-ui/react-switch": "^1.1.2",
Expand Down Expand Up @@ -59,8 +61,8 @@
"react-dom": "^18",
"react-dropzone": "^14.2.3",
"react-force-graph-2d": "^1.26.1",
"react-hook-form": "^7.54.2",
"react-gtm-module": "^2.0.11",
"react-hook-form": "^7.54.2",
"react-json-tree": "^0.19.0",
"react-resizable-panels": "^1.0.9",
"redis": "^4.6.14",
Expand Down

0 comments on commit 5e7c0d2

Please sign in to comment.