Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Update user's data
user.firstName = data.firstName;
user.lastName = data.lastName;
await user.save();
}
try {
await authPlugin.createUser({ data: args.data, user, permanent: true }, context);
result.authUser = true;
} catch {
// Update firstName/lastName, but do not touch the existing password
await authPlugin.updateUser({ data: omit(args.data, ["password"]), user }, context);
}
} catch (e) {
if (e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS) {
const attrError = InvalidFieldsError.from(e);
return new ErrorResponse({
code: attrError.code || WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS,
message: attrError.message,
data: attrError.data
});
}
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data
});
}
return new Response(result);
};
try {
await user.populate(args.data).save();
const authPlugin = context.plugins
.byType("security-authentication-provider")
.filter(pl => pl.hasOwnProperty("createUser"))
.pop();
try {
await authPlugin.createUser({ data: args.data, user }, context);
} catch {
// If user already exists we don't do anything on the auth provider side.
}
} catch (e) {
if (e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS) {
const attrError = InvalidFieldsError.from(e);
return new ErrorResponse({
code: attrError.code || WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS,
message: attrError.message,
data: attrError.data
});
}
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data
});
}
return new Response(user);
};
export default async (root: any, args: Object, context: Object) => {
const { File } = context.models;
const model = await File.findOne({ query: { src: args.src } });
if (!model) {
return new NotFoundResponse();
}
try {
await model.populate(args.data).save();
} catch (e) {
if (
e instanceof WithFieldsError &&
e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS
) {
const attrError = InvalidFieldsError.from(e);
return new ErrorResponse({
code: attrError.code || "VALIDATION_FAILED_INVALID_FIELDS",
message: attrError.message,
data: attrError.data
});
}
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data || null
});
}
return new Response(model);
};
if (!user) {
return new NotFoundResponse(id ? `User "${id}" not found!` : "User not found!");
}
try {
await user.populate(data).save();
const authPlugin = context.plugins
.byType("security-authentication-provider")
.filter(pl => pl.hasOwnProperty("updateUser"))
.pop();
await authPlugin.updateUser({ data: args.data, user }, context);
} catch (e) {
if (e.code === WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS) {
const attrError = InvalidFieldsError.from(e);
return new ErrorResponse({
code: attrError.code || WithFieldsError.VALIDATION_FAILED_INVALID_FIELDS,
message: attrError.message,
data: attrError.data
});
}
return new ErrorResponse({
code: e.code,
message: e.message,
data: e.data
});
}
return new Response(user);
};