upd
This commit is contained in:
@@ -2,6 +2,7 @@ import { Elysia, t } from "elysia";
|
||||
import login from "../services/auth/login";
|
||||
import authMiddleware from "../middlewares/auth";
|
||||
import logout from "../services/auth/logout";
|
||||
import me from "../services/auth/me";
|
||||
|
||||
const authController = new Elysia({ prefix: "/auth" })
|
||||
.post("/login", async ({ body }) => await login(body), {
|
||||
@@ -17,6 +18,7 @@ const authController = new Elysia({ prefix: "/auth" })
|
||||
// }),
|
||||
// })
|
||||
.use(authMiddleware)
|
||||
.get("/me", async ({ auth }) => await me(auth))
|
||||
.get(
|
||||
"/logout",
|
||||
async ({ headers }) => {
|
||||
|
||||
@@ -1,18 +1,6 @@
|
||||
import Elysia from "elysia";
|
||||
import authMiddleware from "../middlewares/auth";
|
||||
import me from "../services/user/me";
|
||||
|
||||
type AuthContext = {
|
||||
auth: {
|
||||
userId: string;
|
||||
};
|
||||
};
|
||||
|
||||
const usersController = new Elysia({ prefix: "/users" })
|
||||
.use(authMiddleware)
|
||||
.get("/me", async (context) => {
|
||||
const userId = (context as AuthContext).auth.userId;
|
||||
return await me(userId);
|
||||
});
|
||||
const usersController = new Elysia({ prefix: "/users" }).use(authMiddleware);
|
||||
|
||||
export default usersController;
|
||||
|
||||
@@ -13,7 +13,9 @@ export default async function createApp(
|
||||
}
|
||||
) {
|
||||
if (auth.userId !== "hmac-user") {
|
||||
return error(403, "Forbidden");
|
||||
return error(403, {
|
||||
error: "Forbidden",
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -22,7 +24,9 @@ export default async function createApp(
|
||||
});
|
||||
|
||||
if (existingApp.length) {
|
||||
return error(400, "App with this name already exists");
|
||||
return error(400, {
|
||||
error: "App with this name already exists",
|
||||
});
|
||||
}
|
||||
|
||||
const apps = await db
|
||||
|
||||
@@ -2,11 +2,12 @@ import { eq } from "drizzle-orm";
|
||||
import db from "../../db";
|
||||
import { usersTable } from "../../db/schema";
|
||||
import { error } from "elysia";
|
||||
import type { AuthContext } from "../../middlewares/auth";
|
||||
|
||||
export default async function me(userId: string) {
|
||||
export default async function me(auth: AuthContext) {
|
||||
try {
|
||||
const user = await db.query.usersTable.findFirst({
|
||||
where: eq(usersTable.id, userId),
|
||||
where: eq(usersTable.id, auth.userId),
|
||||
columns: {
|
||||
id: true,
|
||||
email: true,
|
||||
Reference in New Issue
Block a user