fix: use app name as totp issuer
This commit is contained in:
@@ -8,6 +8,7 @@ import { User } from "@prisma/client";
|
|||||||
import * as argon from "argon2";
|
import * as argon from "argon2";
|
||||||
import { authenticator, totp } from "otplib";
|
import { authenticator, totp } from "otplib";
|
||||||
import * as qrcode from "qrcode-svg";
|
import * as qrcode from "qrcode-svg";
|
||||||
|
import { ConfigService } from "src/config/config.service";
|
||||||
import { PrismaService } from "src/prisma/prisma.service";
|
import { PrismaService } from "src/prisma/prisma.service";
|
||||||
import { AuthService } from "./auth.service";
|
import { AuthService } from "./auth.service";
|
||||||
import { AuthSignInTotpDTO } from "./dto/authSignInTotp.dto";
|
import { AuthSignInTotpDTO } from "./dto/authSignInTotp.dto";
|
||||||
@@ -16,6 +17,7 @@ import { AuthSignInTotpDTO } from "./dto/authSignInTotp.dto";
|
|||||||
export class AuthTotpService {
|
export class AuthTotpService {
|
||||||
constructor(
|
constructor(
|
||||||
private prisma: PrismaService,
|
private prisma: PrismaService,
|
||||||
|
private configService: ConfigService,
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@@ -76,13 +78,10 @@ export class AuthTotpService {
|
|||||||
throw new BadRequestException("TOTP is already enabled");
|
throw new BadRequestException("TOTP is already enabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const issuer = this.configService.get("general.appName");
|
||||||
const secret = authenticator.generateSecret();
|
const secret = authenticator.generateSecret();
|
||||||
|
|
||||||
const otpURL = totp.keyuri(
|
const otpURL = totp.keyuri(user.username || user.email, issuer, secret);
|
||||||
user.username || user.email,
|
|
||||||
"pingvin-share",
|
|
||||||
secret,
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.prisma.user.update({
|
await this.prisma.user.update({
|
||||||
where: { id: user.id },
|
where: { id: user.id },
|
||||||
|
|||||||
Reference in New Issue
Block a user