import { Request } from 'express';

/**
 * Authorizationヘッダに格納された文字列(jwt)を取得します
 * @param {Request}
 * @return {string | undefined}
 */
export const retrieveAuthorizationToken = (
  req: Request,
): string | undefined => {
  const header = req.header('Authorization');

  if (typeof header === 'string') {
    if (header.startsWith('Bearer ')) {
      return header.substring('Bearer '.length, header.length);
    }
  }
  return undefined;
};
