@replyke/express
Version:
Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.
50 lines (49 loc) • 1.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const models_1 = require("../../../models");
exports.default = async (req, res) => {
try {
const { foreignId } = req.query;
if (!foreignId || typeof foreignId !== "string") {
res.status(400).json({
error: "Missing or invalid foreign user ID.",
code: "user/invalid-identifier",
});
return;
}
const projectId = req.project.id;
let user = (await models_1.User.findOne({
where: { foreignId, projectId },
}));
if (!user) {
res.status(404).json({
error: "User not found",
code: "user/not-found",
});
return;
}
// Fetch user again without sensitive fields
const cleanUser = await models_1.User.findByPk(user.id, {
attributes: {
exclude: [
"hash",
"salt",
"email",
"isVerified",
"isActive",
"lastActive",
"secureMetadata",
],
},
});
res.status(200).json(cleanUser?.toJSON());
}
catch (err) {
console.error("Error fetching/creating/updating user:", err);
res.status(500).json({
error: "Internal server error",
code: "user/server-error",
details: err.message,
});
}
};