auth-common 1.0.2 → 1.0.3

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/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "auth-common",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
- "main": "index.js",
5
+ "main": "./build/index.js",
6
+ "types": "./build/index.d.ts",
7
+ "files": [
8
+ "build/**/*"
9
+ ],
6
10
  "scripts": {
7
11
  "clean": "del-cli ./build/*",
8
12
  "build": "npm run clean && tsc",
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./middlewares/UserDetails";
2
- export * from "./middlewares/ValidateUser";
@@ -1,38 +0,0 @@
1
- import { Request, Response, NextFunction } from "express";
2
- import jwt from "jsonwebtoken";
3
-
4
- declare global {
5
- namespace Express {
6
- interface Request {
7
- session?: {
8
- token?: string;
9
- };
10
- currentUser?: {
11
- id: string;
12
- name: string;
13
- email: string;
14
- };
15
- }
16
- }
17
- }
18
-
19
- interface JwtPayload {
20
- id: string;
21
- name: string;
22
- email: string;
23
- }
24
-
25
- export const userDetails = async (
26
- req: Request,
27
- res: Response,
28
- next: NextFunction,
29
- ) => {
30
- try {
31
- const token = req?.session?.token;
32
- const payload = jwt.verify(token!, process.env.TOKEN_SECRET!);
33
- req.currentUser = payload as JwtPayload;
34
- next();
35
- } catch (error) {
36
- next(error);
37
- }
38
- };
@@ -1,14 +0,0 @@
1
- import { NextFunction, Request, Response } from "express";
2
- import { UnauthorizeError } from "error-common";
3
-
4
- export const validateUser = (
5
- req: Request,
6
- res: Response,
7
- next: NextFunction,
8
- ) => {
9
- const token = req.session?.token;
10
- if (!token) {
11
- throw new UnauthorizeError();
12
- }
13
- next();
14
- };
package/tsconfig.json DELETED
@@ -1,15 +0,0 @@
1
- {
2
- // Visit https://aka.ms/tsconfig to read more about this file
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./build",
6
- // "module": "nodenext",
7
- "target": "es2022",
8
- "declaration": true,
9
- "strict": true,
10
- "skipLibCheck": true,
11
- "esModuleInterop": true,
12
- "emitDeclarationOnly": false
13
- },
14
- "include": ["src"]
15
- }