serverpreconfigured 1.0.5 → 1.0.6

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,4 +0,0 @@
1
- export declare enum AuthenticateWSResult {
2
- OK = 1,
3
- InvalidToken = 2
4
- }
@@ -1,7 +1 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var AuthenticateWSResult;
4
- (function (AuthenticateWSResult) {
5
- AuthenticateWSResult[AuthenticateWSResult["OK"] = 1] = "OK";
6
- AuthenticateWSResult[AuthenticateWSResult["InvalidToken"] = 2] = "InvalidToken";
7
- })(AuthenticateWSResult = exports.AuthenticateWSResult || (exports.AuthenticateWSResult = {}));
@@ -1,6 +1,5 @@
1
- import { AuthenticateWSResult } from "./types";
2
1
  export declare function getWSAuthDataByUserId(userId: number): Promise<any>;
3
2
  export declare function setWSAuthDataNewToken(userId: number, expiration_hours?: number): Promise<any>;
4
3
  export declare function checkWSAuthToken(userId: number, token: string): Promise<boolean>;
5
- export declare function authenticateWS(userId: number, token: string, connection_token: string): Promise<AuthenticateWSResult>;
4
+ export declare function authenticateWS(userId: number, token: string, connection_token: string): Promise<boolean>;
6
5
  export declare function checkConnectionAuth(userId: number, connection_token: string): Promise<boolean>;
@@ -12,7 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const server_1 = require("../server");
13
13
  const server_2 = require("../server");
14
14
  const random_1 = require("./../utils/string/random");
15
- const types_1 = require("./types");
16
15
  server_1.WebSocketAuth.init(server_2.dataBase);
17
16
  function getWSAuthDataByUserId(userId) {
18
17
  return __awaiter(this, void 0, void 0, function* () {
@@ -79,11 +78,11 @@ function authenticateWS(userId, token, connection_token) {
79
78
  return __awaiter(this, void 0, void 0, function* () {
80
79
  try {
81
80
  if (!(yield checkWSAuthToken(userId, token)))
82
- return types_1.AuthenticateWSResult.InvalidToken;
81
+ return false;
83
82
  let ws = yield getWSAuthDataByUserId(userId);
84
83
  ws.auth_connection_token = connection_token;
85
84
  yield ws.save();
86
- return types_1.AuthenticateWSResult.OK;
85
+ return true;
87
86
  }
88
87
  catch (e) {
89
88
  throw e;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serverpreconfigured",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "\"Pre-configured server with authentication system and database integration\"",
5
5
  "main": "dist/server.js",
6
6
  "keywords": ["server","pre configured","database","authentication"],
@@ -1,4 +0,0 @@
1
- export enum AuthenticateWSResult{
2
- OK=1,
3
- InvalidToken,
4
- }
@@ -1,7 +1,6 @@
1
1
  import { WebSocketAuth } from "../server";
2
2
  import { dataBase } from "../server";
3
3
  import {randomString} from "./../utils/string/random";
4
- import {AuthenticateWSResult} from "./types";
5
4
  WebSocketAuth.init(dataBase);
6
5
  export async function getWSAuthDataByUserId(userId:number):Promise<any>{
7
6
  try{
@@ -54,14 +53,14 @@ export async function checkWSAuthToken(userId:number,token:string):Promise<boole
54
53
  }
55
54
  }
56
55
 
57
- export async function authenticateWS(userId:number,token:string,connection_token:string):Promise<AuthenticateWSResult>{
56
+ export async function authenticateWS(userId:number,token:string,connection_token:string):Promise<boolean>{
58
57
  try{
59
58
  if(!(await checkWSAuthToken(userId,token)))
60
- return AuthenticateWSResult.InvalidToken;
59
+ return false;
61
60
  let ws=await getWSAuthDataByUserId(userId);
62
61
  ws.auth_connection_token=connection_token;
63
62
  await ws.save();
64
- return AuthenticateWSResult.OK;
63
+ return true;
65
64
  }catch(e){
66
65
  throw e;
67
66
  }