immich/server/src/dtos/auth.dto.ts

138 lines
2.7 KiB
TypeScript
Raw Normal View History

import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { IsEmail, IsNotEmpty, IsString, MinLength } from 'class-validator';
2025-10-07 14:25:18 -04:00
import { AuthApiKey, AuthSession, AuthSharedLink, AuthUser } from 'src/database';
import { ImmichCookie, Permission } from 'src/enum';
import { Optional, PinCode, toEmail, ValidateEnum } from 'src/validation';
2024-04-19 11:19:23 -04:00
export type CookieResponse = {
isSecure: boolean;
values: Array<{ key: ImmichCookie; value: string | null }>;
2024-04-19 11:19:23 -04:00
};
export class AuthDto {
user!: AuthUser;
apiKey?: AuthApiKey;
sharedLink?: AuthSharedLink;
session?: AuthSession;
}
export class LoginCredentialDto {
@IsEmail({ require_tld: false })
@Transform(toEmail)
@IsNotEmpty()
@ApiProperty({ example: 'testuser@email.com' })
email!: string;
@IsString()
@IsNotEmpty()
@ApiProperty({ example: 'password' })
password!: string;
}
export class LoginResponseDto {
accessToken!: string;
userId!: string;
userEmail!: string;
name!: string;
profileImagePath!: string;
isAdmin!: boolean;
shouldChangePassword!: boolean;
isOnboarded!: boolean;
2025-10-07 14:25:18 -04:00
@ValidateEnum({ enum: Permission, name: 'Permission', each: true })
permissions!: Permission[];
}
export class LogoutResponseDto {
successful!: boolean;
redirectUri!: string;
}
export class SignUpDto extends LoginCredentialDto {
@IsString()
@IsNotEmpty()
@ApiProperty({ example: 'Admin' })
name!: string;
}
export class ChangePasswordDto {
@IsString()
@IsNotEmpty()
@ApiProperty({ example: 'password' })
password!: string;
@IsString()
@IsNotEmpty()
@MinLength(8)
@ApiProperty({ example: 'password' })
newPassword!: string;
}
export class PinCodeSetupDto {
@PinCode()
pinCode!: string;
}
export class PinCodeResetDto {
@PinCode({ optional: true })
pinCode?: string;
@Optional()
@IsString()
@IsNotEmpty()
password?: string;
}
2025-05-15 18:08:31 -04:00
export class SessionUnlockDto extends PinCodeResetDto {}
export class PinCodeChangeDto extends PinCodeResetDto {
@PinCode()
newPinCode!: string;
}
export class ValidateAccessTokenResponseDto {
authStatus!: boolean;
}
export class OAuthCallbackDto {
@IsNotEmpty()
@IsString()
@ApiProperty()
url!: string;
@Optional()
@IsString()
state?: string;
@Optional()
@IsString()
codeVerifier?: string;
}
export class OAuthConfigDto {
@IsNotEmpty()
@IsString()
redirectUri!: string;
@Optional()
@IsString()
state?: string;
@Optional()
@IsString()
codeChallenge?: string;
}
export class OAuthAuthorizeResponseDto {
url!: string;
}
export class AuthStatusResponseDto {
pinCode!: boolean;
password!: boolean;
isElevated!: boolean;
2025-05-15 18:08:31 -04:00
expiresAt?: string;
pinExpiresAt?: string;
}