Skip to content

Commit

Permalink
fix(server): session refresh (#8974)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasm91 authored Apr 20, 2024
1 parent fd45147 commit 1e3dcee
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
5 changes: 1 addition & 4 deletions server/src/services/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,7 @@ describe('AuthService', () => {
sessionMock.getByToken.mockResolvedValue(sessionStub.inactive);
sessionMock.update.mockResolvedValue(sessionStub.valid);
const headers: IncomingHttpHeaders = { cookie: 'immich_access_token=auth_token' };
await expect(sut.validate(headers, {})).resolves.toEqual({
user: userStub.user1,
session: sessionStub.valid,
});
await expect(sut.validate(headers, {})).resolves.toBeDefined();
expect(sessionMock.update.mock.calls[0][0]).toMatchObject({ id: 'not_active', updatedAt: expect.any(Date) });
});
});
Expand Down
4 changes: 2 additions & 2 deletions server/src/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,14 @@ export class AuthService {

private async validateSession(tokenValue: string): Promise<AuthDto> {
const hashedToken = this.cryptoRepository.hashSha256(tokenValue);
let session = await this.sessionRepository.getByToken(hashedToken);
const session = await this.sessionRepository.getByToken(hashedToken);

if (session?.user) {
const now = DateTime.now();
const updatedAt = DateTime.fromJSDate(session.updatedAt);
const diff = now.diff(updatedAt, ['hours']);
if (diff.hours > 1) {
session = await this.sessionRepository.update({ id: session.id, updatedAt: new Date() });
await this.sessionRepository.update({ id: session.id, updatedAt: new Date() });
}

return { user: session.user, session: session };
Expand Down

0 comments on commit 1e3dcee

Please sign in to comment.