mirror of
https://github.com/nicotsx/ironmount.git
synced 2025-12-10 12:10:51 +01:00
feat(settings): change password
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
logout,
|
||||
getMe,
|
||||
getStatus,
|
||||
changePassword,
|
||||
listVolumes,
|
||||
createVolume,
|
||||
testConnection,
|
||||
@@ -44,6 +45,8 @@ import type {
|
||||
LogoutResponse,
|
||||
GetMeData,
|
||||
GetStatusData,
|
||||
ChangePasswordData,
|
||||
ChangePasswordResponse,
|
||||
ListVolumesData,
|
||||
CreateVolumeData,
|
||||
CreateVolumeResponse,
|
||||
@@ -283,6 +286,46 @@ export const getStatusOptions = (options?: Options<GetStatusData>) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const changePasswordQueryKey = (options?: Options<ChangePasswordData>) =>
|
||||
createQueryKey("changePassword", options);
|
||||
|
||||
/**
|
||||
* Change current user password
|
||||
*/
|
||||
export const changePasswordOptions = (options?: Options<ChangePasswordData>) => {
|
||||
return queryOptions({
|
||||
queryFn: async ({ queryKey, signal }) => {
|
||||
const { data } = await changePassword({
|
||||
...options,
|
||||
...queryKey[0],
|
||||
signal,
|
||||
throwOnError: true,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
queryKey: changePasswordQueryKey(options),
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Change current user password
|
||||
*/
|
||||
export const changePasswordMutation = (
|
||||
options?: Partial<Options<ChangePasswordData>>,
|
||||
): UseMutationOptions<ChangePasswordResponse, DefaultError, Options<ChangePasswordData>> => {
|
||||
const mutationOptions: UseMutationOptions<ChangePasswordResponse, DefaultError, Options<ChangePasswordData>> = {
|
||||
mutationFn: async (localOptions) => {
|
||||
const { data } = await changePassword({
|
||||
...options,
|
||||
...localOptions,
|
||||
throwOnError: true,
|
||||
});
|
||||
return data;
|
||||
},
|
||||
};
|
||||
return mutationOptions;
|
||||
};
|
||||
|
||||
export const listVolumesQueryKey = (options?: Options<ListVolumesData>) => createQueryKey("listVolumes", options);
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,6 +14,9 @@ import type {
|
||||
GetMeResponses,
|
||||
GetStatusData,
|
||||
GetStatusResponses,
|
||||
ChangePasswordData,
|
||||
ChangePasswordResponses,
|
||||
ChangePasswordErrors,
|
||||
ListVolumesData,
|
||||
ListVolumesResponses,
|
||||
CreateVolumeData,
|
||||
@@ -148,6 +151,22 @@ export const getStatus = <ThrowOnError extends boolean = false>(options?: Option
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Change current user password
|
||||
*/
|
||||
export const changePassword = <ThrowOnError extends boolean = false>(
|
||||
options?: Options<ChangePasswordData, ThrowOnError>,
|
||||
) => {
|
||||
return (options?.client ?? _heyApiClient).post<ChangePasswordResponses, ChangePasswordErrors, ThrowOnError>({
|
||||
url: "/api/v1/auth/change-password",
|
||||
...options,
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
...options?.headers,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* List all volumes
|
||||
*/
|
||||
|
||||
@@ -125,6 +125,39 @@ export type GetStatusResponses = {
|
||||
|
||||
export type GetStatusResponse = GetStatusResponses[keyof GetStatusResponses];
|
||||
|
||||
export type ChangePasswordData = {
|
||||
body?: {
|
||||
currentPassword: string;
|
||||
newPassword: string;
|
||||
};
|
||||
path?: never;
|
||||
query?: never;
|
||||
url: "/api/v1/auth/change-password";
|
||||
};
|
||||
|
||||
export type ChangePasswordErrors = {
|
||||
/**
|
||||
* Invalid current password or validation error
|
||||
*/
|
||||
400: unknown;
|
||||
/**
|
||||
* Not authenticated
|
||||
*/
|
||||
401: unknown;
|
||||
};
|
||||
|
||||
export type ChangePasswordResponses = {
|
||||
/**
|
||||
* Password changed successfully
|
||||
*/
|
||||
200: {
|
||||
message: string;
|
||||
success: boolean;
|
||||
};
|
||||
};
|
||||
|
||||
export type ChangePasswordResponse = ChangePasswordResponses[keyof ChangePasswordResponses];
|
||||
|
||||
export type ListVolumesData = {
|
||||
body?: never;
|
||||
path?: never;
|
||||
|
||||
Reference in New Issue
Block a user