Update landing page

This commit is contained in:
KMKoushik
2024-04-26 10:04:59 +10:00
parent 3b6d2dec25
commit 163aca189b
11 changed files with 354 additions and 74 deletions

View File

@@ -1,8 +1,8 @@
import { createRoute, z } from "@hono/zod-openapi";
import { DomainSchema } from "~/lib/zod/domain-schema";
import { PublicAPIApp } from "../hono";
import { db } from "../../db";
import { getTeamFromToken } from "../auth";
import { PublicAPIApp } from "~/server/public-api/hono";
import { db } from "~/server/db";
import { getTeamFromToken } from "~/server/public-api/auth";
const route = createRoute({
method: "get",

View File

@@ -1,6 +1,6 @@
import { createRoute, z } from "@hono/zod-openapi";
import { PublicAPIApp } from "../hono";
import { getTeamFromToken } from "../auth";
import { PublicAPIApp } from "~/server/public-api/hono";
import { getTeamFromToken } from "~/server/public-api/auth";
import { sendEmail } from "~/server/service/email-service";
const route = createRoute({

View File

@@ -3,6 +3,9 @@ import { hashToken } from "../auth";
import { db } from "../db";
import { UnsendApiError } from "./api-error";
/**
* Gets the team from the token. Also will check if the token is valid.
*/
export const getTeamFromToken = async (c: Context) => {
const authHeader = c.req.header("Authorization");
if (!authHeader) {
@@ -11,7 +14,7 @@ export const getTeamFromToken = async (c: Context) => {
message: "No Authorization header provided",
});
}
const token = authHeader.split(" ")[1]; // Assuming the Authorization header is in the format "Bearer <token>"
const token = authHeader.split(" ")[1];
if (!token) {
throw new UnsendApiError({
code: "UNAUTHORIZED",
@@ -38,5 +41,15 @@ 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(),
},
});
return team;
};

View File

@@ -1,10 +1,13 @@
import { getApp } from "./hono";
import getDomains from "./api/get-domains";
import sendEmail from "./api/send-email";
import getDomains from "./api/domains/get-domains";
import sendEmail from "./api/emails/send-email";
export const app = getApp();
/**Domain related APIs */
getDomains(app);
/**Email related APIs */
sendEmail(app);
export default app;