Skip to content

Commit

Permalink
feat: Extend JWT expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobi2K committed Sep 27, 2023
1 parent c55cef4 commit e235a5a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { User } from 'src/database/entities/user.entity';
UsersModule,
PassportModule,
JwtModule.register({
signOptions: { expiresIn: '7d' },
signOptions: { expiresIn: '14d' },
}),
TypeOrmModule.forFeature([User]),
],
Expand Down
18 changes: 13 additions & 5 deletions src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,20 @@ export class AuthService {
}
}

async getUserByJWT(token: string) {
const decoded = await this.jwtService.verify(token);
const db = await this.usersService.findOne(decoded.name);
if (db) {
return db;
// WIP
async checkJWT(user) {
console.log(user);
const payload = { name: user.username };
if (user.username) {
const token = this.jwtService.sign(payload, {
secret: process.env.JWT_SECRET,
});
return {
access_token: token,
name: user.username,
};
}
return { name: user.username };
}

async updateUserByJWT(body: ChangeNameDto, user: { username: string }) {
Expand Down

0 comments on commit e235a5a

Please sign in to comment.