style(credentials): correct syntax and improve formatting in CredentialsService

This commit corrects a minor syntax error by adding missing semicolons on two lines. It also tidies up code by improving the formatting in the constructor and function signAuthToken.
This commit is contained in:
Mathis H (Avnyr) 2024-07-11 14:59:15 +02:00
parent f681dd77bd
commit 5a5a8c1114
Signed by: Mathis
GPG Key ID: DD9E0666A747D126

View File

@ -2,13 +2,11 @@ import { BadRequestException, Injectable } from "@nestjs/common";
import { ConfigService } from "@nestjs/config"; import { ConfigService } from "@nestjs/config";
import * as argon from "argon2"; import * as argon from "argon2";
import * as jose from "jose"; import * as jose from "jose";
import { generateSecret, JWTPayload } from "jose"; import { JWTPayload, generateSecret } from "jose";
@Injectable() @Injectable()
export class CredentialsService { export class CredentialsService {
constructor( constructor(private readonly configService: ConfigService) {}
private readonly configService: ConfigService,
) {}
async hash(plaintextPassword: string) { async hash(plaintextPassword: string) {
console.log(plaintextPassword); console.log(plaintextPassword);
@ -36,14 +34,16 @@ export class CredentialsService {
} }
async signAuthToken(payload: JWTPayload) { async signAuthToken(payload: JWTPayload) {
console.log(this.configService.get("APP_TOKEN_SECRET")) console.log(this.configService.get("APP_TOKEN_SECRET"));
const token = new jose.SignJWT(payload) const token = new jose.SignJWT(payload)
.setProtectedHeader({ alg: "HS512", enc: "A128CBC-HS512" }) .setProtectedHeader({ alg: "HS512", enc: "A128CBC-HS512" })
.setIssuedAt() .setIssuedAt()
.setExpirationTime("3 day") .setExpirationTime("3 day")
.setIssuer("ShouldStick") .setIssuer("ShouldStick")
.setAudience("auth:user") .setAudience("auth:user");
console.log(token) console.log(token);
return await token.sign(Uint8Array.from(this.configService.get("APP_TOKEN_SECRET"))); return await token.sign(
Uint8Array.from(this.configService.get("APP_TOKEN_SECRET")),
);
} }
} }