Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
feat(nano-server): revert getAuthBearer
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm committed Jan 4, 2024
1 parent 3634e2f commit 1a76b5d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/nano-server/src/nano-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,28 @@ export class AlwatrConnection {
}
}

/**
* Get the token placed in the request header.
*
* Extract token from `Authorization` with `Bearer ` prefix.
*
* @returns token placed in the request header without bearer.
*
* @example
* ```ts
* const token = connection.getAuthBearer();
* ```
*/
getAuthBearer(): string | null {
const auth = this.incomingMessage.headers.authorization?.split(' ');

if (auth == null || auth[0].toLowerCase() !== 'bearer') {
return null;
}

return auth[1];
}

/**
* Get the user authentication information from the incoming message headers.
*
Expand Down

0 comments on commit 1a76b5d

Please sign in to comment.