Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
beforeHandler: async ({ req }: HookOptions) => {
const user = await getAuthenticatedUser({ req, config });
// FYI: user should be able to update itself without permission
if (req.params.id !== user.id) {
await hasPermission({ req, user, config });
}
const payload: any = _pick(Object.keys(schema), req.body);
validateData(rules)(payload);
req.body.password = !_isNil(req.body.password)
? await hashPassword(req.body.password)
: undefined;
req.body.updatedAt = getUtcDate();
},
config,
beforeHandler: async ({ req }: HookOptions) => {
const user = await getAuthenticatedUser({ req, config });
await hasPermission({ req, user, config });
const payload: any = _pick(Object.keys(beforeCreateSchema), req.body);
validateData(rules)(payload);
// user who has permission to create an article is an author
req.body.user_id = user.id;
},
config,
beforeHandler: async ({ req }: HookOptions) => {
const user = await getAuthenticatedUser({ req, config });
// FYI: user should be able to update itself without permission
if (req.params.id !== user.id) {
await hasPermission({ req, user, config });
}
const payload: any = _pick(Object.keys(schema), req.body);
validateData(rules)(payload);
req.body.password = !_isNil(req.body.password)
? await hashPassword(req.body.password)
: undefined;
req.body.updatedAt = getUtcDate();
},
config,
catchErrors(config, async (req, res) => {
const user = await getAuthenticatedUser({ req, config });
await hasPermission({ req, user, config });
const { role_id } = req.params;
const { permission_id } = req.body;
validateData(rules)({ role_id, permission_id });
await config.service.assignRolePermission({
permissionId: permission_id,
roleId: role_id,
});
const translations = config.translator({ req });
res.status(CREATED).json({
message: translations.created(),
});
});
beforeHandler: async ({ req }: HookOptions) => {
const user = await getAuthenticatedUser({ req, config });
if (req.params.id !== user.id) {
await hasPermission({ req, user, config });
}
const payload: any = _pick(Object.keys(config.beforeReplaceSchema), req.body);
validateData(config.beforeReplaceRules)(payload);
req.body.updatedAt = getUtcDate();
},
config,
catchErrors(config, async (req, res) => {
const { email } = req.body;
validateData(rules)({ email });
const { appConfig, translator } = config;
const translations = translator({ req });
const { items } = await config.service.users.getItems({
filter: {
email,
},
});
if (items.length === 0) {
throw new ItemNotFoundError('User');
}
const link = getVerifyEmailUrl({
beforeHandler: async ({ req }: HookOptions) => {
const user = await getAuthenticatedUser({ req, config });
await hasPermission({ req, user, config });
const payload: any = _pick(Object.keys(config.beforeCreateSchema), req.body);
validateData(config.beforeCreateRules)(payload);
},
config,
beforeHandler: async ({ req }: HookOptions) => {
const user = await getAuthenticatedUser({ req, config });
await hasPermission({ req, user, config });
const payload: any = _pick(Object.keys(schema), req.body);
validateData(rules)(payload);
},
config,
catchErrors(config, async (req, res) => {
const payload: any = _pick(Object.keys(schema), req.body);
const { password_confirmation, ...data } = validateData(rules)(payload);
const {
bio,
dateOfBirth,
email,
firstName,
gender,
lastName,
password,
} = toCamel(data);
const { appConfig, translator } = config;
const translations = translator({ req });
const verifyToken = uuid();
catchErrors(config, async (req, res) => {
const payload: any = _pick(Object.keys(schema), req.body);
const { token, password } = validateData(rules)(payload);
const { appConfig, translator } = config;
const translations = translator({ req });
const mailOptions: BaseOptions = {
from: appConfig.repo.mail.from,
html: translations.resetPasswordHtml(),
subject: translations.resetPasswordSubject(),
text: translations.resetPasswordText(),
};
await config.service.auth.resetPassword({
mailOptions,
password,
token,
});