15 lines
451 B
TypeScript
15 lines
451 B
TypeScript
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;
|
||
}
|