Housekeeping

This commit is contained in:
KMKoushik
2024-04-28 09:39:47 +10:00
parent 814d9e9e37
commit e78befd4cf
6 changed files with 29 additions and 50 deletions

View File

@@ -31,7 +31,7 @@ import {
SelectTrigger,
} from "@unsend/ui/src/select";
/* Stupid hydrating error. And I so stupid to understand the stupid NextJS docs. Because they stupid change it everyday */
/* Stupid hydrating error. And I so stupid to understand the stupid NextJS docs */
const DynamicSheetWithNoSSR = dynamic(
() => import("@unsend/ui/src/sheet").then((mod) => mod.Sheet),
{ ssr: false }

View File

@@ -10,9 +10,7 @@ export default async function EmailsPage() {
<div className="flex justify-between items-center">
<h1 className="font-bold text-lg">Emails</h1>
</div>
{/* <Suspense fallback={<div>Loading...</div>}> */}
<EmailList />
{/* </Suspense> */}
</div>
);
}

View File

@@ -1,36 +0,0 @@
import { headers } from "next/headers";
import { hashToken } from "~/server/auth";
import { db } from "~/server/db";
import { sendEmail } from "~/server/service/email-service";
export async function GET() {
return Response.json({ data: "Hello" });
}
export async function POST(req: Request) {
const token = headers().get("authorization")?.split(" ")[1];
console.log(token);
if (!token) {
return new Response("authorization token is required", {
status: 401,
});
}
const hashedToken = hashToken(token);
const team = await db.team.findFirst({
where: {
apiKeys: {
some: {
tokenHash: hashedToken,
},
},
},
});
const data = await req.json();
try {
const email = await sendEmail({ ...data, teamId: team?.id });
return Response.json({ data: email });
} catch (e) {
return Response.json({ error: (e as Error).message }, { status: 500 });
}
}

View File

@@ -42,14 +42,16 @@ export const getTeamFromToken = async (c: Context) => {
}
// No await so it won't block the request. Need to be moved to a queue in future
db.apiKey.update({
where: {
tokenHash: hashedToken,
},
data: {
lastUsed: new Date(),
},
});
db.apiKey
.update({
where: {
tokenHash: hashedToken,
},
data: {
lastUsed: new Date(),
},
})
.catch(console.error);
return team;
};