refactor(profile): changed to patch vs posting
This commit is contained in:
@@ -23,7 +23,7 @@ app.openapi(
|
||||
tags: ["auth:user"],
|
||||
summary: "Updates a users Profile",
|
||||
description: "Currently you can only update your password over the API",
|
||||
method: "post",
|
||||
method: "patch",
|
||||
path: "/profile",
|
||||
middleware: authMiddleware,
|
||||
request: {
|
||||
@@ -38,10 +38,9 @@ app.openapi(
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
message: z
|
||||
.string()
|
||||
.optional()
|
||||
.openapi({ example: "User Profile has been updated" }),
|
||||
message: z.string().optional().openapi({
|
||||
example: "User Profile has been updated",
|
||||
}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
@@ -81,13 +80,16 @@ app.openapi(
|
||||
|
||||
if (authHeader?.includes("Basic")) {
|
||||
return c.json(
|
||||
{ message: "You are a Basic user! Please login to get a token" },
|
||||
{
|
||||
message:
|
||||
"You are a Basic user! Please login to get a token",
|
||||
},
|
||||
401
|
||||
);
|
||||
}
|
||||
|
||||
if (!authHeader) {
|
||||
return c.json({ message: "Unauthorized" }, 401);
|
||||
return c.json({ success: false, message: "Unauthorized" }, 401);
|
||||
}
|
||||
|
||||
const token = authHeader?.split("Bearer ")[1] || "";
|
||||
@@ -103,16 +105,24 @@ app.openapi(
|
||||
"auth",
|
||||
"Failed session check, user must be logged out"
|
||||
);
|
||||
return c.json({ message: "Unauthorized" }, 401);
|
||||
return c.json({ success: false, message: "Unauthorized" }, 401);
|
||||
}
|
||||
|
||||
// now pass all the data over to update the user info
|
||||
try {
|
||||
const data = await c?.req.json();
|
||||
await updateProfile(user, data, token);
|
||||
return c.json({ message: "Your profile has been updated" });
|
||||
return c.json({
|
||||
success: true,
|
||||
message: "Your profile has been updated",
|
||||
});
|
||||
} catch (error) {
|
||||
return c.json({ message: "There was an error", error });
|
||||
console.log(error);
|
||||
return c.json({
|
||||
success: false,
|
||||
message: "There was an error",
|
||||
error,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user