@flowerforce/flowerbase 1.4.2-beta.1 → 1.4.2-beta.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.
@@ -1 +1 @@
1
- {"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../../src/auth/providers/local-userpass/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAqCzC;;;;GAIG;AACH,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,eAAe,iBAsUjE"}
1
+ {"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../../src/auth/providers/local-userpass/controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAqCzC;;;;GAIG;AACH,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,eAAe,iBAqVjE"}
@@ -107,7 +107,23 @@ function localUserPassController(app) {
107
107
  res.status(429).send({ message: 'Too many requests' });
108
108
  return;
109
109
  }
110
- const result = yield (0, handleUserRegistration_1.default)(app, { run_as_system: true, provider: handleUserRegistration_model_1.PROVIDER.LOCAL_USERPASS })({ email: req.body.email.toLowerCase(), password: req.body.password });
110
+ let result;
111
+ try {
112
+ result = yield (0, handleUserRegistration_1.default)(app, { run_as_system: true, provider: handleUserRegistration_model_1.PROVIDER.LOCAL_USERPASS })({
113
+ email: req.body.email.toLowerCase(),
114
+ password: req.body.password
115
+ });
116
+ }
117
+ catch (error) {
118
+ if (error instanceof Error && error.message === 'This email address is already used') {
119
+ res.status(409).send({
120
+ error: 'name already in use',
121
+ error_code: 'AccountNameInUse'
122
+ });
123
+ return;
124
+ }
125
+ throw error;
126
+ }
111
127
  if (!(result === null || result === void 0 ? void 0 : result.insertedId)) {
112
128
  res === null || res === void 0 ? void 0 : res.status(500);
113
129
  throw new Error('Failed to register user');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowerforce/flowerbase",
3
- "version": "1.4.2-beta.1",
3
+ "version": "1.4.2-beta.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -138,7 +138,22 @@ export async function localUserPassController(app: FastifyInstance) {
138
138
  return
139
139
  }
140
140
 
141
- const result = await handleUserRegistration(app, { run_as_system: true, provider: PROVIDER.LOCAL_USERPASS })({ email: req.body.email.toLowerCase(), password: req.body.password })
141
+ let result
142
+ try {
143
+ result = await handleUserRegistration(app, { run_as_system: true, provider: PROVIDER.LOCAL_USERPASS })({
144
+ email: req.body.email.toLowerCase(),
145
+ password: req.body.password
146
+ })
147
+ } catch (error) {
148
+ if (error instanceof Error && error.message === 'This email address is already used') {
149
+ res.status(409).send({
150
+ error: 'name already in use',
151
+ error_code: 'AccountNameInUse'
152
+ })
153
+ return
154
+ }
155
+ throw error
156
+ }
142
157
 
143
158
  if (!result?.insertedId) {
144
159
  res?.status(500)