@vita-mojo/auth 0.0.3-rc.0
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/README.md +11 -0
- package/package.json +12 -0
- package/src/auth.d.ts +8 -0
- package/src/auth.js +8 -0
- package/src/auth.js.map +1 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +2 -0
- package/src/index.js.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# auth
|
|
2
|
+
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
4
|
+
|
|
5
|
+
## Running unit tests
|
|
6
|
+
|
|
7
|
+
Run `nx test auth` to execute the unit tests via [Jest](https://jestjs.io).
|
|
8
|
+
|
|
9
|
+
## Running lint
|
|
10
|
+
|
|
11
|
+
Run `nx lint auth` to execute the lint via [ESLint](https://eslint.org/).
|
package/package.json
ADDED
package/src/auth.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Request } from 'express';
|
|
2
|
+
import * as jwt from 'jsonwebtoken';
|
|
3
|
+
export declare const extractTokenFromRequest: (request: Request) => Promise<string | null>;
|
|
4
|
+
export declare const checkToken: (token: string, secretOrKey: string) => Promise<string | jwt.JwtPayload>;
|
|
5
|
+
export declare const isAllowedRole: (role: {
|
|
6
|
+
slug: string;
|
|
7
|
+
}, allowedRoles: string[]) => boolean;
|
|
8
|
+
export declare const isAllowedPermission: (permissions: string[], allowedPermissions: string[]) => boolean;
|
package/src/auth.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import * as jwt from 'jsonwebtoken';
|
|
3
|
+
import { ExtractJwt } from 'passport-jwt';
|
|
4
|
+
export const extractTokenFromRequest = (request) => __awaiter(void 0, void 0, void 0, function* () { return ExtractJwt.fromAuthHeaderAsBearerToken()(request); });
|
|
5
|
+
export const checkToken = (token, secretOrKey) => __awaiter(void 0, void 0, void 0, function* () { return jwt.verify(token, secretOrKey, { algorithms: ['HS256', 'RS256'] }); });
|
|
6
|
+
export const isAllowedRole = (role, allowedRoles) => allowedRoles.includes(role.slug);
|
|
7
|
+
export const isAllowedPermission = (permissions, allowedPermissions) => permissions.some((permission) => allowedPermissions.includes(permission));
|
|
8
|
+
//# sourceMappingURL=auth.js.map
|
package/src/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../../packages/auth/src/auth.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAO,OAAgB,EAAE,EAAE,kDAChE,OAAA,UAAU,CAAC,2BAA2B,EAAE,CAAC,OAAO,CAAC,CAAA,GAAA,CAAC;AAEpD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAO,KAAa,EAAE,WAAmB,EAAE,EAAE,kDACrE,OAAA,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,CAAA,GAAA,CAAC;AAErE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAsB,EAAE,YAAsB,EAAE,EAAE,CAC9E,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEnC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,WAAqB,EACrB,kBAA4B,EAC5B,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,kBAAkB,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC"}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './auth';
|
package/src/index.js
ADDED
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/auth/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC"}
|