-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ed7361
commit 90afd9b
Showing
21 changed files
with
387 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { prisma } from "../client"; | ||
import crypto from "crypto"; | ||
|
||
export default async function create(user: string) { | ||
return prisma.apiKey.create({ | ||
data: { | ||
user, | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { prisma } from "../client"; | ||
import crypto from "crypto"; | ||
|
||
export default async function deleteOne(apiKeyID: string) { | ||
const apiKey = crypto.randomUUID(); | ||
|
||
return prisma.apiKey.delete({ | ||
where: { | ||
apiKeyID, | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { prisma } from "../client"; | ||
|
||
export default async function getAll() { | ||
return prisma.apiKey.findMany(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Container, Grid } from "@mui/material"; | ||
|
||
import PageTitle from "../../src/components/PageTitle"; | ||
import PageTitleWrapper from "../../src/components/PageTitleWrapper"; | ||
import SuspenseLoader from "../../src/components/SuspenseLoader"; | ||
import ApiKeyTable from "../../src/components/ApiKeyTable"; | ||
|
||
import Head from "next/head"; | ||
|
||
import useSWR, { useSWRConfig } from "swr"; | ||
import { withPageAuthRequired } from "@auth0/nextjs-auth0"; | ||
import { format } from "date-fns"; | ||
import type { ApiKey } from "@prisma/client"; | ||
|
||
const fetcher = async (uri: string) => { | ||
const response = await fetch(uri); | ||
return response.json(); | ||
}; | ||
|
||
export default withPageAuthRequired(function () { | ||
const { data, error, isValidating } = useSWR("/api/apiKeys", fetcher); | ||
|
||
if (isValidating) { | ||
return ( | ||
<Container | ||
sx={{ height: "80vh", display: "flex", justifyContent: "center" }} | ||
> | ||
{/* The default value size is 64 */} | ||
<SuspenseLoader size={64 * 1.5} /> | ||
</Container> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<title>Api Keys</title> | ||
</Head> | ||
<PageTitleWrapper> | ||
<PageTitle | ||
sx={{ width: "auto" }} | ||
heading="API Keys" | ||
subHeading="List of API Keys" | ||
noDoc={true} | ||
/> | ||
</PageTitleWrapper> | ||
<Container | ||
sx={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
justifyContent: "center", | ||
}} | ||
maxWidth="lg" | ||
> | ||
<Grid | ||
container | ||
direction="row" | ||
justifyContent="center" | ||
alignItems="stretch" | ||
spacing={3} | ||
> | ||
<Grid item xs={12}> | ||
<ApiKeyTable apiKeys={data} /> | ||
</Grid> | ||
</Grid> | ||
</Container> | ||
</> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
import getAll from "../../../db/apiKeys"; | ||
import { withApiAuthRequired } from "@auth0/nextjs-auth0"; | ||
import type { ApiKey } from "@prisma/client"; | ||
|
||
export default withApiAuthRequired(async function ( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
if (req.method !== "POST") { | ||
return res.status(403).send("Incorrect HTTP code"); | ||
} | ||
|
||
let records: ApiKey[]; | ||
|
||
try { | ||
records = await getAll(); | ||
} catch (e) { | ||
console.error(e); | ||
return res.status(400).send("Unauthorized, Api-Key not found."); | ||
} | ||
|
||
return res.status(200).json({ data: records }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
import deleteOne from "../../../db/apiKeys/deleteOne"; | ||
import { withApiAuthRequired } from "@auth0/nextjs-auth0"; | ||
import type { ApiKey } from "@prisma/client"; | ||
|
||
export default withApiAuthRequired(async function ( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
if (req.method !== "DELETE") { | ||
return res.status(403).send("Incorrect HTTP code"); | ||
} | ||
|
||
const apiKeyID = req.body.apiKeyID; | ||
|
||
let records: ApiKey; | ||
|
||
try { | ||
records = await deleteOne(apiKeyID); | ||
} catch (e) { | ||
console.error(e); | ||
return res.status(400).send("Unauthorized, Api-Key not found."); | ||
} | ||
|
||
return res.status(200).json({ data: records }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
import getAll from "../../../db/apiKeys"; | ||
import { withApiAuthRequired } from "@auth0/nextjs-auth0"; | ||
import type { ApiKey } from "@prisma/client"; | ||
|
||
export default withApiAuthRequired(async function ( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
if (req.method !== "GET") { | ||
return res.status(403).send("Incorrect HTTP code"); | ||
} | ||
|
||
let records: ApiKey[]; | ||
|
||
try { | ||
records = await getAll(); | ||
} catch (e) { | ||
console.error(e); | ||
return res.status(400).send("Unauthorized, Api-Key not found."); | ||
} | ||
|
||
return res.status(200).json({ data: records }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
90afd9b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
hedgefund-dashboard – ./
hedgefund-dashboard-milesthedisch-gmailcom.vercel.app
hedgefund-dashboard-git-master-milesthedisch-gmailcom.vercel.app
hedgefund-dashboard.vercel.app