Update TypeScript configuration for stricter type checks and modify environment variable access. Exclude additional directories from compilation, enhance error handling in resolvers, and improve random element selection in mock data generation. Refactor locale handling in middleware and update GraphQL client to use bracket notation for environment variables.
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import jwt from "jsonwebtoken";
|
||||
import type { JWTPayload, UserRole } from "../types/user.js";
|
||||
import jwt, { type SignOptions } from "jsonwebtoken";
|
||||
import type { JWTPayload } from "../types/user.js";
|
||||
import { UserRole } from "../types/user.js";
|
||||
import { logger } from "../monitoring/logger.js";
|
||||
|
||||
const JWT_SECRET =
|
||||
process.env.JWT_SECRET || "your-secret-key-change-in-production";
|
||||
const JWT_EXPIRES_IN = process.env.JWT_EXPIRES_IN || "7d";
|
||||
const JWT_SECRET: string =
|
||||
process.env["JWT_SECRET"] || "your-secret-key-change-in-production";
|
||||
const JWT_EXPIRES_IN: string = process.env["JWT_EXPIRES_IN"] || "7d";
|
||||
|
||||
/**
|
||||
* Erstellt ein JWT Token für einen User
|
||||
@@ -12,7 +13,7 @@ const JWT_EXPIRES_IN = process.env.JWT_EXPIRES_IN || "7d";
|
||||
export function createToken(payload: JWTPayload): string {
|
||||
return jwt.sign(payload, JWT_SECRET, {
|
||||
expiresIn: JWT_EXPIRES_IN,
|
||||
});
|
||||
} as SignOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,7 +43,7 @@ export function extractTokenFromHeader(
|
||||
return null;
|
||||
}
|
||||
|
||||
return parts[1];
|
||||
return parts[1] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import type {
|
||||
User,
|
||||
UserRole,
|
||||
LoginCredentials,
|
||||
RegisterData,
|
||||
} from "../types/user.js";
|
||||
import type { User, LoginCredentials, RegisterData } from "../types/user.js";
|
||||
import { UserRole } from "../types/user.js";
|
||||
import { hashPassword, comparePassword } from "./password.js";
|
||||
import { createToken, verifyToken } from "./jwt.js";
|
||||
import { logger } from "../monitoring/logger.js";
|
||||
@@ -22,7 +18,7 @@ export class UserService {
|
||||
*/
|
||||
async register(
|
||||
data: RegisterData,
|
||||
role: UserRole = "customer"
|
||||
role: UserRole = UserRole.CUSTOMER
|
||||
): Promise<{
|
||||
user: User;
|
||||
token: string;
|
||||
|
||||
Reference in New Issue
Block a user