Restructure backend into modular API layers with admin/organizador/invitados routes, add role-based middleware, flatten module models, and update build scripts
This commit is contained in:
27
packages/legacy/src/core/services/token.service.ts
Normal file
27
packages/legacy/src/core/services/token.service.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { AuthToken } from '../entities/token.entity';
|
||||
|
||||
@Injectable()
|
||||
export class TokenService {
|
||||
// En una implementación real esto debería usar el repositorio de MikroORM.
|
||||
private tokens: AuthToken[] = [];
|
||||
|
||||
createToken(name?: string, expiresInHours?: number): AuthToken {
|
||||
const token = new AuthToken();
|
||||
token.token = uuidv4();
|
||||
token.name = name;
|
||||
if (expiresInHours) {
|
||||
token.expiresAt = new Date(Date.now() + expiresInHours * 60 * 60 * 1000);
|
||||
}
|
||||
this.tokens.push(token);
|
||||
return token;
|
||||
}
|
||||
|
||||
validate(tokenString: string): AuthToken | null {
|
||||
const token = this.tokens.find((t) => t.token === tokenString);
|
||||
if (!token) return null;
|
||||
if (token.expiresAt && token.expiresAt < new Date()) return null;
|
||||
return token;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user