本文整理汇总了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);
}
示例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;
}
}
示例3: createToken
async createToken() {
const user: JwtPayload = { email: 'test@email.com' };
const accessToken = this.jwtService.sign(user);
return {
expiresIn: 3600,
accessToken,
};
}
示例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');
}
}
示例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');
}
}
示例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 };
}
示例7: createToken
public async createToken(user: User): Promise<string> {
return this.jwtService.sign({username: user.username});
}