當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript JwtService.sign方法代碼示例

本文整理匯總了TypeScript中@nestjs/jwt.JwtService.sign方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript JwtService.sign方法的具體用法?TypeScript JwtService.sign怎麽用?TypeScript JwtService.sign使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@nestjs/jwt.JwtService的用法示例。


在下文中一共展示了JwtService.sign方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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.sign方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。