Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save adrian-ub/4311ac4eaded21238d035d8c497b35e8 to your computer and use it in GitHub Desktop.
Save adrian-ub/4311ac4eaded21238d035d8c497b35e8 to your computer and use it in GitHub Desktop.
Strapi get /me with relations
"use strict";
/**
* User.js controller
*
* @description: A set of functions called "actions" for managing `User`.
*/
const { sanitizeEntity } = require("strapi-utils");
const sanitizeUser = (user) =>
sanitizeEntity(user, {
model: strapi.query("user", "users-permissions").model,
});
module.exports = {
async me(ctx) {
const user = ctx.state.user;
if (!user) {
return ctx.badRequest(null, [
{ messages: [{ id: "No authorization header was found" }] },
]);
}
let data = await strapi.plugins["users-permissions"].services.user.fetch({
id: user.id,
});
if (data) {
data = sanitizeUser(data);
}
ctx.send(data);
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment