mirror of
				https://github.com/KevinMidboe/immich.git
				synced 2025-10-29 17:40:28 +00:00 
			
		
		
		
	feat(web,server): logout all devices (#2415)
* feat: logout all devices * chore: regenerate openapi * chore: add test * chore: logout vs log out
This commit is contained in:
		@@ -357,6 +357,18 @@ describe('AuthService', () => {
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  describe('logoutDevices', () => {
 | 
			
		||||
    it('should logout all devices', async () => {
 | 
			
		||||
      userTokenMock.getAll.mockResolvedValue([userTokenEntityStub.inactiveToken, userTokenEntityStub.userToken]);
 | 
			
		||||
 | 
			
		||||
      await sut.logoutDevices(authStub.user1);
 | 
			
		||||
 | 
			
		||||
      expect(userTokenMock.getAll).toHaveBeenCalledWith(authStub.user1.id);
 | 
			
		||||
      expect(userTokenMock.delete).toHaveBeenCalledWith(authStub.user1.id, 'not_active');
 | 
			
		||||
      expect(userTokenMock.delete).not.toHaveBeenCalledWith(authStub.user1.id, 'token-id');
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  describe('logoutDevice', () => {
 | 
			
		||||
    it('should logout the device', async () => {
 | 
			
		||||
      await sut.logoutDevice(authStub.user1, 'token-1');
 | 
			
		||||
 
 | 
			
		||||
@@ -163,6 +163,16 @@ export class AuthService {
 | 
			
		||||
    await this.userTokenCore.delete(authUser.id, deviceId);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async logoutDevices(authUser: AuthUserDto): Promise<void> {
 | 
			
		||||
    const devices = await this.userTokenCore.getAll(authUser.id);
 | 
			
		||||
    for (const device of devices) {
 | 
			
		||||
      if (device.id === authUser.accessTokenId) {
 | 
			
		||||
        continue;
 | 
			
		||||
      }
 | 
			
		||||
      await this.userTokenCore.delete(authUser.id, device.id);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private getBearerToken(headers: IncomingHttpHeaders): string | null {
 | 
			
		||||
    const [type, token] = (headers.authorization || '').split(' ');
 | 
			
		||||
    if (type.toLowerCase() === 'bearer') {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user