feat: create from template

This commit is contained in:
Mythie
2024-02-20 19:46:18 +11:00
parent 4c5b910a59
commit b9e5905469
8 changed files with 242 additions and 70 deletions

View File

@ -22,9 +22,14 @@ export const getUserByApiToken = async ({ token }: { token: string }) => {
throw new Error('Invalid token');
}
const tokenObject = user.ApiToken.find((apiToken) => apiToken.token === hashedToken);
const retrievedToken = user.ApiToken.find((apiToken) => apiToken.token === hashedToken);
if (!tokenObject || new Date(tokenObject.expires) < new Date()) {
// This should be impossible but we need to satisfy TypeScript
if (!retrievedToken) {
throw new Error('Invalid token');
}
if (retrievedToken.expires && retrievedToken.expires < new Date()) {
throw new Error('Expired token');
}