skapi-js 1.0.31 → 1.0.33

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.
package/js/main/skapi.js CHANGED
@@ -23,7 +23,7 @@ export default class Skapi {
23
23
  set user(value) {
24
24
  }
25
25
  constructor(service, owner, options, __etc) {
26
- this.version = '1.0.31';
26
+ this.version = '1.0.33';
27
27
  this.session = null;
28
28
  this.connection = null;
29
29
  this.host = 'skapi';
@@ -342,16 +342,35 @@ export async function recoverAccount(redirect = false) {
342
342
  return 'SUCCESS: Recovery e-mail has been sent.';
343
343
  }
344
344
  export async function jwtLogin(params) {
345
- let { hashedPassword } = request.bind(this)("jwt-login", params);
346
- return login.bind(this)({ email: params.client_id, password: hashedPassword });
345
+ let { hashedPassword, username } = request.bind(this)("jwt-login", params);
346
+ try {
347
+ return login.bind(this)({ username: username, password: hashedPassword });
348
+ }
349
+ catch (err) {
350
+ if (err.code === 'INCORRECT_USERNAME_OR_PASSWORD') {
351
+ throw new SkapiError('User has migrated the account. Login with the service username and password.', { code: 'INVALID_REQUEST' });
352
+ }
353
+ }
347
354
  }
348
355
  export async function login(form) {
349
356
  await this.logout();
350
357
  let params = validator.Params(form, {
351
358
  username: 'string',
352
- email: (v) => validator.Email(v),
359
+ email: 'string',
353
360
  password: (v) => validator.Password(v)
354
- }, ['email', 'password']);
361
+ }, ['password']);
362
+ if (params.email) {
363
+ try {
364
+ validator.Email(params.email);
365
+ }
366
+ catch (err) {
367
+ params.username = params.email;
368
+ delete params.email;
369
+ }
370
+ }
371
+ if (!params.username && !params.email) {
372
+ throw new SkapiError('Least one of "username" or "email" is required.', { code: 'INVALID_PARAMETER' });
373
+ }
355
374
  return authentication.bind(this)().authenticateUser(params.username || params.email, params.password);
356
375
  }
357
376
  export async function signup(form, option) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skapi-js",
3
- "version": "1.0.31",
3
+ "version": "1.0.33",
4
4
  "description": "Skapi: Backend API Library for HTML frontend.",
5
5
  "main": "./dist/skapi.module.js",
6
6
  "types": "./js/Main.d.ts",