2024-08-19 20:06:38 +02:00
|
|
|
import { apiRoute, applyConfig, auth } from "@/api";
|
2024-08-27 20:14:10 +02:00
|
|
|
import { createRoute } from "@hono/zod-openapi";
|
|
|
|
|
import { User } from "~/packages/database-interface/user";
|
|
|
|
|
import { ErrorSchema } from "~/types/api";
|
2023-10-16 05:51:29 +02:00
|
|
|
|
|
|
|
|
export const meta = applyConfig({
|
2024-04-07 07:30:49 +02:00
|
|
|
route: "/api/v1/accounts/verify_credentials",
|
|
|
|
|
ratelimits: {
|
|
|
|
|
max: 100,
|
|
|
|
|
duration: 60,
|
|
|
|
|
},
|
|
|
|
|
auth: {
|
|
|
|
|
required: true,
|
|
|
|
|
oauthPermissions: ["read:accounts"],
|
|
|
|
|
},
|
2023-10-16 05:51:29 +02:00
|
|
|
});
|
2023-09-22 04:15:12 +02:00
|
|
|
|
2024-08-27 20:14:10 +02:00
|
|
|
const route = createRoute({
|
|
|
|
|
method: "get",
|
|
|
|
|
path: "/api/v1/accounts/verify_credentials",
|
|
|
|
|
summary: "Verify credentials",
|
|
|
|
|
description: "Get your own account information",
|
|
|
|
|
middleware: [auth(meta.auth)],
|
|
|
|
|
responses: {
|
|
|
|
|
200: {
|
|
|
|
|
description: "Account",
|
|
|
|
|
content: {
|
|
|
|
|
"application/json": {
|
|
|
|
|
schema: User.schema,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
401: {
|
|
|
|
|
description: "Unauthorized",
|
|
|
|
|
content: {
|
|
|
|
|
"application/json": {
|
|
|
|
|
schema: ErrorSchema,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2024-08-19 20:06:38 +02:00
|
|
|
export default apiRoute((app) =>
|
2024-08-27 20:14:10 +02:00
|
|
|
app.openapi(route, (context) => {
|
|
|
|
|
// TODO: Add checks for disabled/unverified accounts
|
|
|
|
|
const { user } = context.get("auth");
|
2023-09-22 04:15:12 +02:00
|
|
|
|
2024-08-27 20:14:10 +02:00
|
|
|
if (!user) {
|
|
|
|
|
return context.json({ error: "Unauthorized" }, 401);
|
|
|
|
|
}
|
2023-09-22 04:15:12 +02:00
|
|
|
|
2024-08-27 20:14:10 +02:00
|
|
|
return context.json(user.toApi(true), 200);
|
|
|
|
|
}),
|
2024-08-19 20:06:38 +02:00
|
|
|
);
|