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