Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public async use (@Req() req: Req, @EndpointInfo() endpoint: EndpointInfo) {
  2.         // const options = endpoint.get(FirebaseAuth) || {};
  3.         const token: string = this.getToken(req);
  4.         try {
  5.             await this.app.auth().verifyIdToken(token)
  6.         } catch (e) {
  7.             $log.error(e);
  8.             throw(new Unauthorized('Decoding token failed'));
  9.         }
  10.  
  11.     }
  12.  
  13.     private getToken(req: Req): string {
  14.         if (req.headers.authorization  && req.headers.authorization.split(' ')[0] === 'Bearer') {
  15.             return req.headers.authorization.split(' ')[1];
  16.         }
  17.         $log.error('Token not found');
  18.         throw(new Unauthorized('Token not found'));
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement