aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc/routers/apiKeys.ts
diff options
context:
space:
mode:
authorkamtschatka <simon.schatka@gmx.at>2024-09-21 21:17:12 +0200
committerGitHub <noreply@github.com>2024-09-21 20:17:12 +0100
commit26521b70a79c42442f44c8053590bbb8c5e5f1b1 (patch)
treebdcf9cf835c16e76cc520d92c2e261ca8526746e /packages/trpc/routers/apiKeys.ts
parent9dd6f216ad18c09a28eaad67411d3a0e7f57a04f (diff)
downloadkarakeep-26521b70a79c42442f44c8053590bbb8c5e5f1b1.tar.zst
feature(extension): Allow login directly with an API key
* [Feature request] NextAuth Providers for OAuth/SSO #92 Added API key based authentication to the extension to make the extension usable when OAuth is in use * Minor UI tweak --------- Co-authored-by: MohamedBassem <me@mbassem.com>
Diffstat (limited to 'packages/trpc/routers/apiKeys.ts')
-rw-r--r--packages/trpc/routers/apiKeys.ts11
1 files changed, 10 insertions, 1 deletions
diff --git a/packages/trpc/routers/apiKeys.ts b/packages/trpc/routers/apiKeys.ts
index deeb108f..81e3bb2b 100644
--- a/packages/trpc/routers/apiKeys.ts
+++ b/packages/trpc/routers/apiKeys.ts
@@ -4,7 +4,7 @@ import { z } from "zod";
import { apiKeys } from "@hoarder/db/schema";
-import { generateApiKey, validatePassword } from "../auth";
+import { authenticateApiKey, generateApiKey, validatePassword } from "../auth";
import { authedProcedure, publicProcedure, router } from "../index";
const zApiKeySchema = z.object({
@@ -81,4 +81,13 @@ export const apiKeysAppRouter = router({
}
return await generateApiKey(input.keyName, user.id);
}),
+ validate: publicProcedure
+ .input(z.object({ apiKey: z.string() }))
+ .output(z.object({ success: z.boolean() }))
+ .mutation(async ({ input }) => {
+ await authenticateApiKey(input.apiKey); // Throws if the key is invalid
+ return {
+ success: true,
+ };
+ }),
});