@vasrefil/api-toolkit 1.13.6 → 1.13.8

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.
@@ -5,6 +5,11 @@ export declare const UserApiResp: {
5
5
  status: Status;
6
6
  message: string;
7
7
  };
8
+ NO_AUTHORIZATION_TOKEN: {
9
+ code: string;
10
+ status: Status;
11
+ message: string;
12
+ };
8
13
  NOT_AUTHORIZED: {
9
14
  code: string;
10
15
  status: Status;
@@ -6,6 +6,9 @@ exports.UserApiResp = {
6
6
  NO_AUTHORIZATION_HEADER: {
7
7
  code: 'NAH0401', status: status_interface_1.Status.UN_AUTHORIZED, message: 'Please specify authorization header'
8
8
  },
9
+ NO_AUTHORIZATION_TOKEN: {
10
+ code: 'NAT0401', status: status_interface_1.Status.UN_AUTHORIZED, message: 'Please specify authorization token'
11
+ },
9
12
  NOT_AUTHORIZED: {
10
13
  code: 'NA00401', status: status_interface_1.Status.UN_AUTHORIZED, message: 'You are not authorized'
11
14
  },
@@ -14,6 +14,12 @@ class AdminAuthMidWare_ extends _root_service_1.RootService {
14
14
  super(...arguments);
15
15
  this.get_admin = async (req) => {
16
16
  try {
17
+ const authHeader = req.headers.authorization;
18
+ if (!authHeader)
19
+ throw user_response_1.UserApiResp.NO_AUTHORIZATION_HEADER;
20
+ const token = authHeader.split(' ')[1];
21
+ if (!token)
22
+ throw user_response_1.UserApiResp.NO_AUTHORIZATION_TOKEN;
17
23
  const baseurl = env_1.default.VASREFIL.BASEURL;
18
24
  delete req.headers['host'];
19
25
  delete req.headers['content-length'];
@@ -45,6 +51,7 @@ class AdminAuthMidWare_ extends _root_service_1.RootService {
45
51
  next();
46
52
  }
47
53
  catch (error) {
54
+ console.log('validate_auth_error', error);
48
55
  const { status, message, data } = this.get_error(error);
49
56
  return this.sendResponse({ req, res, status, actionType, message, data, error });
50
57
  }
@@ -26,7 +26,7 @@ const routes = (app) => {
26
26
  //use router middleware
27
27
  app.use(router);
28
28
  app.all('*', (req, res) => {
29
- console.log(req.url);
29
+ console.log(`Method: ${req.method}, URL: ${req.url}`);
30
30
  res.status(404).json({ status: 404, error: 'not found' });
31
31
  });
32
32
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vasrefil/api-toolkit",
3
3
  "description": "This is Vasrefil API toolkit",
4
- "version": "1.13.6",
4
+ "version": "1.13.8",
5
5
  "author": "Sodiq Alabi",
6
6
  "main": "dist/public-api.js",
7
7
  "types": "dist/public-api.d.ts",