Was able to get it working
by creating:
src/api/profile/controllers/profile.ts
export default {
async update(ctx) {
try {
const user = ctx.state.user;
if (!user) {
return ctx.unauthorized("You must be logged in");
}
const updatedUser = await strapi.db.query("plugin::users-permissions.user").update({
where: { id: user.id },
data: ctx.request.body,
});
ctx.body = { data: updatedUser };
} catch (err) {
console.error("Profile update error:", err);
ctx.internalServerError("Something went wrong");
}
},
};
src/api/profile/routes/profile.ts
export default {
routes: [
{
method: "PUT",
path: "/profile",
handler: "profile.update",
config: {
auth: { scope: [] }, // requires auth
},
},
],
};
then on Roles "users & Permissions Plugin"
scroll down to find api::profile plugin
http://localhost:1337/admin/settings/users-permissions/roles/1
then enable "Update" on Profiles.
for the request:
PUT {{url}}/api/profile
header: Authorization: bearer <token>
body { "username": "updated name" }
It's working but I'm not sure if this was the recommended way.
If anyone has better answer please give. Thank you