Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const handleSubmit = async e => {
e.preventDefault();
const schema = forms[authType].schema;
let formErrors = {};
try {
await schema.validate(modifiedData, { abortEarly: false });
try {
if (modifiedData.news === true) {
await request('https://analytics.strapi.io/register', {
method: 'POST',
body: omit(modifiedData, ['password', 'confirmPassword']),
signal,
});
}
} catch (err) {
// Do nothing
}
try {
const requestEndPoint = forms[authType].endPoint;
const requestURL = `/admin/auth/${requestEndPoint}`;
const body = omit(modifiedData, 'news');
if (authType === 'forgot-password') {
set(body, 'url', `${strapi.remoteURL}/auth/reset-password`);
});
}
} catch (err) {
// Do nothing
}
try {
const requestEndPoint = forms[authType].endPoint;
const requestURL = `/admin/auth/${requestEndPoint}`;
const body = omit(modifiedData, 'news');
if (authType === 'forgot-password') {
set(body, 'url', `${strapi.remoteURL}/auth/reset-password`);
}
const { jwt, user, ok } = await request(requestURL, {
method: 'POST',
body,
signal,
});
if (authType === 'forgot-password' && ok === true) {
dispatch({
type: 'SUBMIT_SUCCESS',
email: modifiedData.email,
});
} else {
auth.setToken(jwt, modifiedData.rememberMe);
auth.setUserInfo(user, modifiedData.rememberMe);
}
} catch (err) {
const formattedError = formatErrorFromRequest(err);
files.forEach(file => {
formData.append(`files.${key}`, file);
});
});
// Change the request helper default headers so we can pass a FormData
const headers = {};
const method = isCreatingEntry ? 'POST' : 'PUT';
const endPoint = isCreatingEntry ? slug : `${slug}/${id}`;
emitEvent(isCreatingEntry ? 'willCreateEntry' : 'willEditEntry');
try {
// Time to actually send the data
await request(
getRequestUrl(endPoint),
{
method,
headers,
body: formData,
signal,
},
false,
false
);
emitEvent(isCreatingEntry ? 'didCreateEntry' : 'didEditEntry');
dispatch({
type: 'SUBMIT_SUCCESS',
});
redirectToPreviousPage();
} catch (err) {
Object.keys(filesToUpload).forEach(key => {
const files = filesToUpload[key];
files.forEach(file => {
formData.append(`files.${key}`, file);
});
});
// Change the request helper default headers so we can pass a FormData
const headers = {};
const method = isCreatingEntry ? 'POST' : 'PUT';
const endPoint = isCreatingEntry ? slug : `${slug}/${id}`;
try {
// Time to actually send the data
await request(
getRequestUrl(endPoint),
{
method,
headers,
params: { source },
body: formData,
signal,
},
false,
false
);
emitEvent('didSaveEntry');
redirectToPreviousPage();
} catch (err) {
const error = get(
err,
async function didGetSecuredData() {
const { updatePlugin } = this.props;
const requestURL = `/${pluginId}/models`;
try {
const {
models: { models },
} = await request(requestURL, { method: 'GET' });
const menu = [
{
name: 'Content Types',
links: map(omit(models, 'plugins'), (model, key) => ({
label: model.labelPlural || model.label || key,
destination: key,
})),
},
];
updatePlugin(pluginId, 'leftMenuSections', menu);
} catch (err) {
strapi.notification.error('content-manager.error.model.fetch');
}
}
const updateAppMenu = async () => {
const requestURL = '/content-manager/content-types';
try {
const { data } = await request(requestURL, { method: 'GET' });
const menu = [{ name: 'Content Types', links: data }];
updatePlugin('content-manager', 'leftMenuSections', menu);
} catch (err) {
console.error({ err });
strapi.notification.error('notification.error');
}
};
const handleSubmit = async e => {
e.preventDefault();
let formErrors = {};
const schema = forms[slug].schema;
try {
await schema.validate(modifiedData, { abortEarly: false });
if (!isEmpty(body)) {
try {
await request(
`/${pluginId}/${endPoint}`,
{ method: 'PUT', body, params: { source: 'db' } },
true
);
emitEvent('willEditSettings', { category: endPoint });
dispatch({
type: 'SUBMIT_SUCCEEDED',
});
strapi.notification.success(
getTrad('strapi.notification.success.settingsEdit')
);
} catch (err) {
strapi.notification.error('notification.error');
}
}
} catch (err) {
const getData = async () => {
try {
const { data } = await request(
getRequestUrl(`${type}/${slug || componentSlug}`),
{
method: 'GET',
signal,
}
);
dispatch({
type: 'GET_DATA_SUCCEEDED',
data: data.contentType || data.component,
componentLayouts: data.components,
});
} catch (err) {
if (err.code !== 20) {
strapi.notification.error('notification.error');
}
const getData = async () => {
try {
const requestURL = '/users-permissions/init';
const { hasAdmin } = await request(requestURL, { method: 'GET' });
const { data } = await request('/admin/init', { method: 'GET' });
const { uuid } = data;
if (uuid) {
await fetch('https://analytics.strapi.io/track', {
method: 'POST',
body: JSON.stringify({
event: 'didInitializeAdministration',
uuid,
}),
headers: {
'Content-Type': 'application/json',
},
});
}
getDataRef.current(hasAdmin, data);
const handleClick = async lang => {
try {
const locale = findLangTrad(lang);
await request(
`/${pluginId}/configurations/i18n`,
{ method: 'PUT', body: { 'language.defaultLocale': locale.value } },
true
);
setShouldRefetch(prev => !prev);
} catch (err) {
strapi.notification.error('notification.error');
}
};
const handleDeleteLanguage = async () => {