251209:1453 Frontend: progress nest = UAT & Bug Fixing
Some checks failed
Spec Validation / validate-markdown (push) Has been cancelled
Spec Validation / validate-diagrams (push) Has been cancelled
Spec Validation / check-todos (push) Has been cancelled

This commit is contained in:
admin
2025-12-09 14:53:42 +07:00
parent 8aceced902
commit aa96cd90e3
125 changed files with 11052 additions and 785 deletions

View File

@@ -19,9 +19,9 @@ import type { Cache } from 'cache-manager';
import * as bcrypt from 'bcrypt';
import * as crypto from 'crypto';
import { UserService } from '../../modules/user/user.service.js';
import { UserService } from '../../modules/user/user.service';
import { User } from '../../modules/user/entities/user.entity';
import { RegisterDto } from './dto/register.dto.js';
import { RegisterDto } from './dto/register.dto';
import { RefreshToken } from './entities/refresh-token.entity'; // [P2-2]
@Injectable()
@@ -230,4 +230,43 @@ export class AuthService {
return { message: 'Logged out successfully' };
}
// [New] Get Active Sessions
async getActiveSessions() {
// Only return tokens that are NOT revoked and NOT expired
const activeTokens = await this.refreshTokenRepository.find({
where: {
isRevoked: false,
},
relations: ['user'], // Ensure relations: ['user'] works if RefreshToken entity has relation
order: { createdAt: 'DESC' },
});
const now = new Date();
// Filter expired tokens in memory if query builder is complex, or rely on where clause if possible.
// Since we want to return mapped data:
return activeTokens
.filter((t) => t.expiresAt > now)
.map((t) => ({
id: t.tokenId.toString(),
userId: t.userId,
user: {
username: t.user?.username || 'Unknown',
first_name: t.user?.firstName || '',
last_name: t.user?.lastName || '',
},
deviceName: 'Unknown Device', // Not stored in DB
ipAddress: 'Unknown IP', // Not stored in DB
lastActive: t.createdAt.toISOString(), // Best approximation
isCurrent: false, // Cannot determine isCurrent without current session context match
}));
}
// [New] Revoke Session by ID
async revokeSession(sessionId: number) {
return this.refreshTokenRepository.update(
{ tokenId: sessionId },
{ isRevoked: true }
);
}
}