79780501

Date: 2025-10-01 21:57:00
Score: 1
Natty:
Report link

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

Reasons:
  • Blacklisted phrase (0.5): Thank you
  • RegEx Blacklisted phrase (2.5): please give
  • Long answer (-1):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • High reputation (-1):
Posted by: Evan