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

@@ -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;
};