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;Functions Reference
handleLogin
handleLoginArguments
username
string
โ
The username to attempt login with.
password
string
โ
The user's password.
Returns
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
handleRegisterExample
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
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
useCurrentUserExample
Returns
username
string
Current login username
accountData
unknown
Return data provided while registering
Last updated