DEFINING GLOBAL TYPES

To ensure Type Safety throughout the application and allow the TypeScript compiler to recognize the new global authentication functions (such as handleLogin and handleRegister), we must extend the global type declarations.

Implementation

Open the file web/src/types.d.ts and add the following type declarations starting from handleLogin down to useSignOut. These definitions inform TypeScript about the existence, arguments, and return types of these functions, preventing compilation errors in the views and hooks.

declare function handleLogin(
    username: string,
    password: string
): Promise<{ success: boolean; message: string; }>;

declare function handleRegister(
    username: string,
    password: string,
    accountData: unknown,
): Promise<{ success: boolean; message: string; }>;

declare function useCurrentUser(): { username: string; accountData: unknown } | null;

declare function useIsAuthenticated(): boolean;
declare function useSignOut(): void;

Note: The existing utility declarations (e.g., openGalleryPicker, startCall, useSettings, etc.) already present in types.d.ts should remain untouched. You only need to append the new authentication declarations listed above.

Functions Reference

handleLogin

Arguments

Name
Type
Optional
Description

username

string

โŒ

The username to attempt login with.

password

string

โŒ

The user's password.

Returns

Name
Type
Description

success

boolean

The success boolean is true upon success.

message

string

The message string provides an error description (if unsuccessful) or a confirmation message.

handleRegister

Example

Arguments

username

string

โŒ

The username for the new registration.

password

string

โŒ

The new user's password.

accountData

unknown

โœ…

Optional additional account data to be saved (e.g., email, date of birth). Can be null.

Returns

Name
Type
Description

success

boolean

The success boolean is true upon success.

message

string

The message string provides an error description (if unsuccessful) or a confirmation message.

useCurrentUser

Example

Returns

Name
Type
Description

username

string

Current login username

accountData

unknown

Return data provided while registering

Last updated