v1.0.0 #28

Merged
bizcochito merged 147 commits from develop into main 2024-01-14 19:49:34 +00:00
1 changed files with 9 additions and 10 deletions
Showing only changes of commit c428e956bc - Show all commits

View File

@ -2,9 +2,9 @@ import jwt from "jsonwebtoken";
import AuthService from "../services/AuthService";
import { Request, Response, NextFunction } from "express";
const authTokenSecret = process.env.JWTSECRET || "badsecret";
class AuthControler {
authTokenSecret = process.env.JWTSECRET || "badsecret";
async login(req: Request, res: Response) {
// Read app and secret from request body
const { app, secret } = req.body;
@ -15,7 +15,11 @@ class AuthControler {
if (authenticated) {
console.log("Authenticated app ", authenticated.app);
// Generate an access token
const accessToken = jwt.sign({ app: authenticated.app }, authTokenSecret);
const accessToken = jwt.sign(
{ app: authenticated.app },
this.authTokenSecret,
{ expiresIn: "1h" }
);
res.json({
accessToken,
@ -30,17 +34,12 @@ class AuthControler {
if (authHeader) {
const token = authHeader.split(" ")[1];
jwt.verify(token, authTokenSecret, (err, user) => {
jwt.verify(token, this.authTokenSecret, (err, app) => {
if (err) {
return res.status(403).json("Invalid token provided");
}
console.log(
"Authorization provided for ",
next.name,
" to user ",
user
);
console.log("Authorization provided for ", next.name, " to app ", app);
next();
});
} else {