@adminforth/open-signup 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.js +10 -9
  2. package/index.ts +17 -19
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -143,17 +143,17 @@ export default class OpenSignupPlugin extends AdminForthPlugin {
143
143
  const { token, password } = body;
144
144
  const { email } = yield this.adminforth.auth.verify(token, 'tempVerifyEmailToken', false);
145
145
  if (!email) {
146
- return { error: 'Invalid token', ok: false };
146
+ return { error: yield tr('Invalid token', 'opensignup'), ok: false };
147
147
  }
148
148
  if (!password) {
149
- return { error: tr('Password is required', 'opensignup'), ok: false };
149
+ return { error: yield tr('Password is required', 'opensignup'), ok: false };
150
150
  }
151
151
  const userRecord = yield this.adminforth.resource(this.authResource.resourceId).get(Filters.EQ(this.emailField.name, email));
152
152
  if (!userRecord) {
153
- return { error: tr('User not found'), ok: false };
153
+ return { error: yield tr('User not found', 'opensignup'), ok: false };
154
154
  }
155
155
  if (userRecord[this.options.confirmEmails.emailConfirmedField]) {
156
- return { error: tr('Email already confirmed'), ok: false };
156
+ return { error: yield tr('Email already confirmed', 'opensignup'), ok: false };
157
157
  }
158
158
  yield this.adminforth.resource(this.authResource.resourceId).update(userRecord[this.authResource.columns.find((col) => col.primaryKey).name], {
159
159
  [this.options.confirmEmails.emailConfirmedField]: true,
@@ -210,9 +210,9 @@ export default class OpenSignupPlugin extends AdminForthPlugin {
210
210
  }
211
211
  // create user
212
212
  if (!existingUser) {
213
+ let recordToCreate = Object.assign(Object.assign(Object.assign({}, (this.options.defaultFieldValues || {})), (this.options.confirmEmails ? { [this.options.confirmEmails.emailConfirmedField]: false } : {})), { [this.emailField.name]: normalizedEmail, [this.options.passwordHashField]: password ? yield AdminForth.Utils.generatePasswordHash(password) : '' });
213
214
  if ((_b = this.options.hooks) === null || _b === void 0 ? void 0 : _b.beforeUserSave) {
214
215
  const hook = this.options.hooks.beforeUserSave;
215
- const recordToCreate = Object.assign(Object.assign(Object.assign({}, (this.options.defaultFieldValues || {})), (this.options.confirmEmails ? { [this.options.confirmEmails.emailConfirmedField]: false } : {})), { [this.emailField.name]: normalizedEmail, [this.options.passwordHashField]: password ? yield AdminForth.Utils.generatePasswordHash(password) : '' });
216
216
  const resp = yield hook({
217
217
  resource: this.authResource,
218
218
  record: recordToCreate,
@@ -225,8 +225,9 @@ export default class OpenSignupPlugin extends AdminForthPlugin {
225
225
  if (resp.error) {
226
226
  return { error: resp.error };
227
227
  }
228
+ recordToCreate = resp.record || recordToCreate;
228
229
  }
229
- const created = yield this.adminforth.resource(this.authResource.resourceId).create(Object.assign(Object.assign(Object.assign({}, (this.options.defaultFieldValues || {})), (this.options.confirmEmails ? { [this.options.confirmEmails.emailConfirmedField]: false } : {})), { [this.emailField.name]: normalizedEmail, [this.options.passwordHashField]: password ? yield AdminForth.Utils.generatePasswordHash(password) : '' }));
230
+ const created = yield this.adminforth.resource(this.authResource.resourceId).create(recordToCreate);
230
231
  if ((_c = this.options.hooks) === null || _c === void 0 ? void 0 : _c.afterUserSave) {
231
232
  const hook = this.options.hooks.afterUserSave;
232
233
  const resp = yield hook({
@@ -251,7 +252,7 @@ export default class OpenSignupPlugin extends AdminForthPlugin {
251
252
  const brandName = this.adminforth.config.customization.brandName;
252
253
  const verifyToken = this.adminforth.auth.issueJWT({ email, issuer: brandName }, 'tempVerifyEmailToken', '2h');
253
254
  process.env.HEAVY_DEBUG && console.log('🐛Sending reset tok to', verifyToken);
254
- const emailText = tr(`
255
+ const emailText = yield tr(`
255
256
  Dear user,
256
257
  Welcome to {brandName}!
257
258
 
@@ -266,7 +267,7 @@ export default class OpenSignupPlugin extends AdminForthPlugin {
266
267
  The {brandName} Team
267
268
 
268
269
  `, 'opensignup', { brandName, url, verifyToken });
269
- const emailHtml = tr(`
270
+ const emailHtml = yield tr(`
270
271
  <html>
271
272
  <head></head>
272
273
  <body>
@@ -281,7 +282,7 @@ export default class OpenSignupPlugin extends AdminForthPlugin {
281
282
  </body>
282
283
  </html>
283
284
  `, 'opensignup', { brandName, url, verifyToken });
284
- const emailSubject = tr(`Signup request at {brandName}`, 'opensignup', { brandName });
285
+ const emailSubject = yield tr(`Signup request at {brandName}`, 'opensignup', { brandName });
285
286
  // send email with AWS SES this.options.providerOptions.AWS_SES
286
287
  this.options.confirmEmails.adapter.sendEmail(this.options.confirmEmails.sendFrom, email, emailText, emailHtml, emailSubject);
287
288
  return { ok: true };
package/index.ts CHANGED
@@ -165,19 +165,19 @@ export default class OpenSignupPlugin extends AdminForthPlugin {
165
165
  const { token, password } = body;
166
166
  const { email } = await this.adminforth.auth.verify(token, 'tempVerifyEmailToken', false);
167
167
  if (!email) {
168
- return { error: 'Invalid token', ok: false };
168
+ return { error: await tr('Invalid token', 'opensignup'), ok: false };
169
169
  }
170
170
 
171
171
  if(!password) {
172
- return { error: tr('Password is required', 'opensignup'), ok: false };
172
+ return { error: await tr('Password is required', 'opensignup'), ok: false };
173
173
  }
174
174
  const userRecord = await this.adminforth.resource(this.authResource.resourceId).get(Filters.EQ(this.emailField.name, email));
175
175
  if (!userRecord) {
176
- return { error: tr('User not found'), ok: false };
176
+ return { error: await tr('User not found', 'opensignup'), ok: false };
177
177
  }
178
178
 
179
179
  if (userRecord[this.options.confirmEmails.emailConfirmedField]) {
180
- return { error: tr('Email already confirmed'), ok: false };
180
+ return { error: await tr('Email already confirmed', 'opensignup'), ok: false };
181
181
  }
182
182
 
183
183
  await this.adminforth.resource(this.authResource.resourceId).update(userRecord[this.authResource.columns.find((col) => col.primaryKey).name], {
@@ -238,14 +238,15 @@ export default class OpenSignupPlugin extends AdminForthPlugin {
238
238
 
239
239
  // create user
240
240
  if (!existingUser) {
241
+ let recordToCreate = {
242
+ ...(this.options.defaultFieldValues || {}),
243
+ ...(this.options.confirmEmails ? { [this.options.confirmEmails.emailConfirmedField]: false } : {}),
244
+ [this.emailField.name]: normalizedEmail,
245
+ [this.options.passwordHashField]: password ? await AdminForth.Utils.generatePasswordHash(password) : '',
246
+ };
247
+
241
248
  if (this.options.hooks?.beforeUserSave) {
242
249
  const hook = this.options.hooks.beforeUserSave;
243
- const recordToCreate = {
244
- ...(this.options.defaultFieldValues || {}),
245
- ...(this.options.confirmEmails ? { [this.options.confirmEmails.emailConfirmedField]: false } : {}),
246
- [this.emailField.name]: normalizedEmail,
247
- [this.options.passwordHashField]: password ? await AdminForth.Utils.generatePasswordHash(password) : '',
248
- };
249
250
  const resp = await hook({
250
251
  resource: this.authResource,
251
252
  record: recordToCreate,
@@ -259,13 +260,10 @@ export default class OpenSignupPlugin extends AdminForthPlugin {
259
260
  if (resp.error) {
260
261
  return { error: resp.error };
261
262
  }
263
+ recordToCreate = resp.record || recordToCreate;
262
264
  }
263
- const created = await this.adminforth.resource(this.authResource.resourceId).create({
264
- ...(this.options.defaultFieldValues || {}),
265
- ...(this.options.confirmEmails ? { [this.options.confirmEmails.emailConfirmedField]: false } : {}),
266
- [this.emailField.name]: normalizedEmail,
267
- [this.options.passwordHashField]: password ? await AdminForth.Utils.generatePasswordHash(password) : '',
268
- });
265
+
266
+ const created = await this.adminforth.resource(this.authResource.resourceId).create(recordToCreate);
269
267
 
270
268
  if (this.options.hooks?.afterUserSave) {
271
269
  const hook = this.options.hooks.afterUserSave;
@@ -296,7 +294,7 @@ export default class OpenSignupPlugin extends AdminForthPlugin {
296
294
 
297
295
  const verifyToken = this.adminforth.auth.issueJWT({email, issuer: brandName }, 'tempVerifyEmailToken', '2h');
298
296
  process.env.HEAVY_DEBUG && console.log('🐛Sending reset tok to', verifyToken);
299
- const emailText = tr(`
297
+ const emailText = await tr(`
300
298
  Dear user,
301
299
  Welcome to {brandName}!
302
300
 
@@ -313,7 +311,7 @@ export default class OpenSignupPlugin extends AdminForthPlugin {
313
311
  `, 'opensignup', { brandName, url, verifyToken }
314
312
  );
315
313
 
316
- const emailHtml = tr(`
314
+ const emailHtml = await tr(`
317
315
  <html>
318
316
  <head></head>
319
317
  <body>
@@ -329,7 +327,7 @@ export default class OpenSignupPlugin extends AdminForthPlugin {
329
327
  </html>
330
328
  `, 'opensignup', { brandName, url, verifyToken });
331
329
 
332
- const emailSubject = tr(`Signup request at {brandName}`, 'opensignup', { brandName });
330
+ const emailSubject = await tr(`Signup request at {brandName}`, 'opensignup', { brandName });
333
331
 
334
332
  // send email with AWS SES this.options.providerOptions.AWS_SES
335
333
  this.options.confirmEmails.adapter.sendEmail(this.options.confirmEmails.sendFrom, email, emailText, emailHtml, emailSubject);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/open-signup",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",