Files
ColdBreeze-chat-web/src/types/auth.ts
T
haorwen 210a34b33c feat: 增加passkey支持 (#270)
* chore: add .pnpm-store to .gitignore

* feat: implement passkey authentication and management features

- Added passkey login and registration endpoints to the auth service.
- Introduced PasskeyManagement component for user passkey management.
- Updated localization files to include passkey-related strings in English and Chinese.
- Created utility functions for handling passkey operations in WebAuthn.
- Adjusted login page to support passkey login flow.
- Modified configuration for local development server.

* feat: enhance passkey management with modal input and localization updates

- Added a modal for entering passkey names during registration in the PasskeyManagement component.
- Updated English and Chinese localization files to include new strings for passkey name input.
- Improved user experience by validating passkey name input before registration.

* feat: enhance passkey login experience with localization updates

- Added new localization strings for passkey authentication errors and status messages in English and Chinese.
- Updated the login page to utilize localized strings for improved user feedback during passkey login attempts.

* feat: add name field to UserPasskey interface for enhanced user identification

* feat: integrate passkey support across login and settings

- Added passkey option to login configuration and updated related components to conditionally render passkey login button.
- Enhanced MyAccount and Logins components to manage passkey settings and display passkey management options based on configuration.
- Updated English and Chinese localization files to include new strings for passkey functionality.

* feat: added server version check for passkey
2025-12-12 21:25:49 +08:00

136 lines
2.7 KiB
TypeScript

import { User } from "./user";
export interface AuthToken {
// common
server_id: string;
token: string;
refresh_token: string;
expired_in: number;
}
export interface RenewTokenDTO extends Pick<AuthToken, "token" | "refresh_token"> {}
export interface RenewTokenResponse
extends Pick<AuthToken, "token" | "refresh_token" | "expired_in"> {}
export interface AuthData extends AuthToken {
initialized?: boolean;
user: User;
}
export type PasswordCredential = {
email: string;
password: string;
type: "password";
};
export type MagicLinkCredential = {
magic_token: string;
extra_name?: string;
type: "magiclink";
};
export type GoogleCredential = {
id_token: string;
magic_token?: string | null;
type: "google";
};
export type GithubCredential = {
code: string;
magic_token?: string | null;
type: "github";
};
export type OIDCCredential = {
code: string;
state: string;
magic_token?: string | null;
type: "oidc";
};
export type MetamaskCredential = {
public_address: string;
nonce: string;
signature: string;
magic_token?: string | null;
type: "metamask";
};
export type ThirdPartyCredential = {
key: string;
type: "thirdparty";
};
export type PasskeyCredential = {
challenge_id: string;
credential: PublicKeyCredentialWithResponse;
type: "passkey";
};
export type LoginCredential =
| PasswordCredential
| OIDCCredential
| MetamaskCredential
| GithubCredential
| GoogleCredential
| ThirdPartyCredential
| MagicLinkCredential
| PasskeyCredential;
export type CredentialResponse = {
password: boolean;
google: string;
metamask: string;
oidc: string[];
};
export interface OIDCConfig {
enable: boolean;
favicon: string;
domain: string;
}
// Passkey types
export interface PublicKeyCredentialWithResponse {
id: string;
rawId: string;
response: {
clientDataJSON: string;
attestationObject?: string;
authenticatorData?: string;
signature?: string;
userHandle?: string | null;
};
type: string;
}
export interface PasskeyRegisterStartRequest {
name: string;
}
export interface PasskeyRegisterStartResponse {
challenge_id: string;
options: {
publicKey: PublicKeyCredentialCreationOptions;
};
}
export interface PasskeyRegisterFinishRequest {
challenge_id: string;
credential: PublicKeyCredentialWithResponse;
name: string;
}
export interface PasskeyLoginStartRequest {
}
export interface PasskeyLoginStartResponse {
challenge_id: string;
options: {
publicKey: PublicKeyCredentialRequestOptions;
};
}
export interface PasskeyLoginFinishRequest {
challenge_id: string;
authentication: PublicKeyCredentialWithResponse;
}
export interface UserPasskey {
id: number;
credential_id: string;
name: string;
created_at: string;
last_used_at?: string;
}