mirror of
https://github.com/immich-app/immich.git
synced 2025-04-22 13:08:08 +02:00
fix(server): session refresh (#8974)
This commit is contained in:
parent
fd4514711f
commit
1e3dceea4d
@ -340,10 +340,7 @@ describe('AuthService', () => {
|
|||||||
sessionMock.getByToken.mockResolvedValue(sessionStub.inactive);
|
sessionMock.getByToken.mockResolvedValue(sessionStub.inactive);
|
||||||
sessionMock.update.mockResolvedValue(sessionStub.valid);
|
sessionMock.update.mockResolvedValue(sessionStub.valid);
|
||||||
const headers: IncomingHttpHeaders = { cookie: 'immich_access_token=auth_token' };
|
const headers: IncomingHttpHeaders = { cookie: 'immich_access_token=auth_token' };
|
||||||
await expect(sut.validate(headers, {})).resolves.toEqual({
|
await expect(sut.validate(headers, {})).resolves.toBeDefined();
|
||||||
user: userStub.user1,
|
|
||||||
session: sessionStub.valid,
|
|
||||||
});
|
|
||||||
expect(sessionMock.update.mock.calls[0][0]).toMatchObject({ id: 'not_active', updatedAt: expect.any(Date) });
|
expect(sessionMock.update.mock.calls[0][0]).toMatchObject({ id: 'not_active', updatedAt: expect.any(Date) });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -374,14 +374,14 @@ export class AuthService {
|
|||||||
|
|
||||||
private async validateSession(tokenValue: string): Promise<AuthDto> {
|
private async validateSession(tokenValue: string): Promise<AuthDto> {
|
||||||
const hashedToken = this.cryptoRepository.hashSha256(tokenValue);
|
const hashedToken = this.cryptoRepository.hashSha256(tokenValue);
|
||||||
let session = await this.sessionRepository.getByToken(hashedToken);
|
const session = await this.sessionRepository.getByToken(hashedToken);
|
||||||
|
|
||||||
if (session?.user) {
|
if (session?.user) {
|
||||||
const now = DateTime.now();
|
const now = DateTime.now();
|
||||||
const updatedAt = DateTime.fromJSDate(session.updatedAt);
|
const updatedAt = DateTime.fromJSDate(session.updatedAt);
|
||||||
const diff = now.diff(updatedAt, ['hours']);
|
const diff = now.diff(updatedAt, ['hours']);
|
||||||
if (diff.hours > 1) {
|
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 };
|
return { user: session.user, session: session };
|
||||||
|
Loading…
x
Reference in New Issue
Block a user