Skip to content

Commit

Permalink
fix: fix token expiry date
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-trajanovski committed Mar 24, 2023
1 parent 0e7cecc commit fc97bd4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export class AuthService {
}

async login(user: Omit<User, "password">): Promise<Record<string, unknown>> {
const accessToken = this.jwtService.sign(user);
const expiresIn = this.configService.get<number>("jwt.expiresIn");
const accessToken = this.jwtService.sign(user, { expiresIn });
return {
access_token: accessToken,
id: accessToken,
Expand Down
7 changes: 6 additions & 1 deletion src/policies/policies.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,15 @@ export class PoliciesService implements OnModuleInit {
}

async create(createPolicyDto: CreatePolicyDto): Promise<Policy> {
const username = (this.request.user as JWTUser).username;
const username = (this.request.user as JWTUser)?.username;
if (!username) {
throw new UnauthorizedException("User not present in the request");
}

const createdPolicy = new this.policyModel(
addCreatedByFields(createPolicyDto, username),
);

return createdPolicy.save();
}

Expand Down

0 comments on commit fc97bd4

Please sign in to comment.