Skip to content

Commit

Permalink
Merge pull request #404 from SciCatProject/fix-token-expiry-date
Browse files Browse the repository at this point in the history
fix: fix token expiry date
  • Loading branch information
nitrosx authored Mar 28, 2023
2 parents 7b8c49b + 1144ca5 commit 4145dba
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 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
3 changes: 2 additions & 1 deletion src/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
UseInterceptors,
Put,
UnauthorizedException,
Body,
} from "@nestjs/common";
import { ApiBearerAuth, ApiBody, ApiTags } from "@nestjs/swagger";
import { Action } from "src/casl/action.enum";
Expand Down Expand Up @@ -105,7 +106,7 @@ export class UsersController {
@Put("/:id/settings")
async updateSettings(
@Param("id") userId: string,
updateUserSettingsDto: UpdateUserSettingsDto,
@Body() updateUserSettingsDto: UpdateUserSettingsDto,
): Promise<UserSettings | null> {
return this.usersService.findOneAndUpdateUserSettings(
userId,
Expand Down

0 comments on commit 4145dba

Please sign in to comment.