16 lines
467 B
TypeScript
16 lines
467 B
TypeScript
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
|
|
import { Request } from 'express';
|
|
|
|
/**
|
|
* Get the token from the response.
|
|
*/
|
|
export const Token = createParamDecorator(
|
|
(data: unknown, ctx: ExecutionContext) => {
|
|
const request = ctx.switchToHttp().getRequest() as Request;
|
|
const authHeader = request.header('authorization');
|
|
if (!authHeader) return null;
|
|
const [, token] = authHeader.split(' ');
|
|
return token;
|
|
},
|
|
);
|