refactor: share authentication result type

This commit is contained in:
2026-10-01 20:53:00 +03:00
parent 15a3d5f331
commit fb2e851e7e
3 changed files with 14 additions and 12 deletions
+6 -6
View File
@@ -12,7 +12,7 @@ import { HttpErrorCode } from '../../../common/error-code';
import { isPrismaErrorCode, PrismaErrorCode } from '../../../prisma/prisma-error-code';
import { PrismaService } from '../../../prisma/prisma.service';
import { AuthErrorCode } from './auth-error-code';
import { AuthUser, RefreshPayload } from './auth.types';
import { AuthenticationResult, AuthUser, RefreshPayload } from './auth.types';
const EXPECTED_ROTATED_SESSIONS = 1;
@@ -35,7 +35,7 @@ export class AuthService {
async register(
email: string,
password: string,
): Promise<{ accessToken: string; refreshToken: string; user: AuthUser }> {
): Promise<AuthenticationResult> {
const existing = await this.prisma.user.findUnique({
where: { email },
});
@@ -64,7 +64,7 @@ export class AuthService {
async login(
email: string,
password: string,
): Promise<{ accessToken: string; refreshToken: string; user: AuthUser }> {
): Promise<AuthenticationResult> {
const user = await this.prisma.user.findUnique({
where: { email },
});
@@ -80,7 +80,7 @@ export class AuthService {
async refresh(
token: string,
): Promise<{ accessToken: string; refreshToken: string; user: AuthUser }> {
): Promise<AuthenticationResult> {
let payload: RefreshPayload;
try {
payload = await this.jwt.verifyAsync<RefreshPayload>(token, {
@@ -151,7 +151,7 @@ export class AuthService {
private async createSession(
user: User,
): Promise<{ accessToken: string; refreshToken: string; user: AuthUser }> {
): Promise<AuthenticationResult> {
const session = await this.prisma.session.create({
data: {
id: randomUUID(),
@@ -166,7 +166,7 @@ export class AuthService {
private async rotateSession(
session: Session & { user: User },
expectedRefreshTokenHash?: string,
): Promise<{ accessToken: string; refreshToken: string; user: AuthUser }> {
): Promise<AuthenticationResult> {
const refreshToken = await this.jwt.signAsync(
{
sub: session.userId,