@martian-tickets/common
v1.0.42
Published
npm install @martian-tickets/common
Readme
How to use
install the package
npm install @martian-tickets/common
create the augment
In you service/microservice create the augment: .../src/express-augment.ts
import { UserPayload } from "./models/user-payload";
declare global {
namespace Express {
interface Request {
currentUser?: UserPayload;
}
}
}
export {};create UserPayload interface
Create models for UserPayload .../src/models/user-payload.ts
export interface UserPayload {
id: string;
email: string;
}Check tsconfig.json
check if the tsconfig.json file follow the pattern
{
"compilerOptions": {
"typeRoots": ["./types", "./node_modules/@types"],
...
},
"include": ["src"]
}remove any "src" keyword in "typeRoots" and "types" field
Check if install the package @types/cookie-session and cookie-session
Use the middleware
for example currentUser:
import express from "express";
// import { currentUser } from "@sgtickets/common";
import { currentUser } from "@martian-tickets/common";
import "@martian-tickets/common";
const router = express.Router();
router.get("/api/users/currentuser", currentUser, (req, res) => {
res.send({ currentUser: req.currentUser || null });
});see the list of common middlewares and error type in the microservice's ...\YOU_MICROSERVICE_DIRECTORY\node_modules@martian-tickets\common\build
