Files
IdP/apps/api-gateway/src/auth-token.ts
2026-06-24 14:37:15 +03:00

15 lines
451 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { UnauthorizedException } from '@nestjs/common';
export function extractBearerToken(authorization?: string): string {
if (!authorization?.startsWith('Bearer ')) {
throw new UnauthorizedException('Не передан токен доступа');
}
const token = authorization.slice('Bearer '.length).trim();
if (!token) {
throw new UnauthorizedException('Не передан токен доступа');
}
return token;
}