Authentication middleware. Light, fast and secure. Writed with native Typescript code and no dependencies are used.
- npm run pack
- Copy the file "package_name-x.x.x.tgz" in the project root folder.
- In the "package.json" file insert: "@cimo/package_name": "file:package_name-x.x.x.tgz"
- npm run build
- npm login --auth-type=legacy
- npm publish --auth-type=legacy --access public
- Link for npm package -> https://www.npmjs.com/package/@cimo/authentication
- Server.ts
...
import { Ca } from "@cimo/authentication";
...
app.use(CookieParser());
...
app.get("/login", (_, response: Express.Response) => {
Ca.writeCookie("xxx_authentication", response);
response.json({ stdout: "Token created." });
});
app.get("/profile", Ca.authenticationMiddleware, (_, response: Express.Response) => {
response.json({ stdout: "Authentication ok." });
});
app.get("/logout", (request: Express.Request, response: Express.Response) => {
Ca.removeCookie("xxx_authentication", request, response);
response.json({ stdout: "Token removed." });
});
...