当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript jwt.JwtService类代码示例

本文整理汇总了TypeScript中@nestjs/jwt.JwtService的典型用法代码示例。如果您正苦于以下问题:TypeScript JwtService类的具体用法?TypeScript JwtService怎么用?TypeScript JwtService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了JwtService类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: createToken

  private createToken(user: User): string {
    const payload: ITokenPayloadUnsigned = {
      uid: user.userId
    };

    return this.jwtService.sign(payload);
  }
开发者ID:jonathan-patalano,项目名称:blog-api,代码行数:7,代码来源:auth.service.ts

示例2: signIn

 public async signIn(user: UserDTO): Promise<string> {
   const userFound: UserDTO = await this.usersService.signIn(user);
   if (userFound) {
     return this.jwtService.sign({ username: userFound.username });
   } else {
     return null;
   }
 }
开发者ID:CaptainShisha,项目名称:REST-API,代码行数:8,代码来源:auth.service.ts

示例3: createToken

 async createToken() {
   const user: JwtPayload = { email: 'test@email.com' };
   const accessToken = this.jwtService.sign(user);
   return {
     expiresIn: 3600,
     accessToken,
   };
 }
开发者ID:SARAVANA1501,项目名称:nest,代码行数:8,代码来源:auth.service.ts

示例4: signIn

 public async signIn(user: UserLoginDTO): Promise<string> {
   const userFound: GetUserDTO = await this.usersService.signIn(user);
   if (userFound) {
     return this.jwtService.sign({ username: userFound.username, roles: [userFound.role]});
   } else {
     throw new NotFoundException('Wrong credentials');
   }
 }
开发者ID:mbechev,项目名称:Feedback,代码行数:8,代码来源:auth.service.ts

示例5: signIn

 public async signIn(user: UserLoginDTO): Promise<string> {
   const userFound: User = await this.usersService.signIn(user);
   if (userFound) {
     console.log(userFound);
     const accessToken = this.jwtService.sign({ username: userFound.username, role: userFound.role.role });
     return accessToken;
   } else {
     throw new NotFoundException('Wrong credentials');
   }
 }
开发者ID:bobby616,项目名称:MovieDB,代码行数:10,代码来源:authentication.service.ts

示例6: createToken

 /**
  * Used during login, this creates a JWT bearer token for this user.
  *
  * @returns a token if the user credentials are verified
  */
 createToken(user: User) {
   const expiresIn = this.config.get('JWT_EXPIRATION') || 3600;
   const accessToken = this.jwtService.sign({
     // These properties will be encoded into the token
     id: user.id,
     email: user.email,
     name: user.name,
     role: user.role,
     clubId: user.clubId
   }, { expiresIn: expiresIn });
   return { expiresIn, accessToken };
 }
开发者ID:OysteinAmundsen,项目名称:gymsystems,代码行数:17,代码来源:auth.service.ts

示例7: use

  use(req: IncomingMessage, res: Response, next: Function) {
    if (!req['user'] && req.headers.authorization) {
      const authToken = req.headers.authorization.substr('Bearer '.length);
      req['user'] = this.jwtService.decode(authToken);
    }

    const requestContext = new RequestContext(req, res);
    const namespace = getNamespace(RequestContext.nsid) || createNamespace(RequestContext.nsid);

    namespace.run(() => {
      namespace.set('RequestContext', requestContext);
      next();
    });
  }
开发者ID:OysteinAmundsen,项目名称:gymsystems,代码行数:14,代码来源:request-context.middleware.ts

示例8: createToken

 public async createToken(user: User): Promise<string> {
   return this.jwtService.sign({username: user.username});
 }
开发者ID:arner,项目名称:saevis,代码行数:3,代码来源:auth.service.ts


注:本文中的@nestjs/jwt.JwtService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。