@@ -0,0 +1,23 @@
|
||||
import {useMutation} from '@tanstack/react-query';
|
||||
import {BackendResponse} from '@common/http/backend-response/backend-response';
|
||||
import {apiClient} from '@common/http/query-client';
|
||||
import {showHttpErrorToast} from '@common/utils/http/show-http-error-toast';
|
||||
|
||||
interface Response extends BackendResponse {}
|
||||
|
||||
interface Payload {
|
||||
password: string;
|
||||
}
|
||||
|
||||
export function useLogoutOtherSessions() {
|
||||
return useMutation({
|
||||
mutationFn: (payload: Payload) => logoutOther(payload),
|
||||
onError: r => showHttpErrorToast(r),
|
||||
});
|
||||
}
|
||||
|
||||
function logoutOther(payload: Payload): Promise<Response> {
|
||||
return apiClient
|
||||
.post('user-sessions/logout-other', payload)
|
||||
.then(response => response.data);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import {useQuery} from '@tanstack/react-query';
|
||||
import {apiClient} from '@common/http/query-client';
|
||||
import {BackendResponse} from '@common/http/backend-response/backend-response';
|
||||
|
||||
export interface ActiveSession {
|
||||
id: string;
|
||||
platform?: string;
|
||||
device_type?: 'mobile' | 'tablet' | 'desktop';
|
||||
browser?: string;
|
||||
country?: string;
|
||||
city?: string;
|
||||
ip_address?: string;
|
||||
token?: string;
|
||||
is_current_device: boolean;
|
||||
last_active: string;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
interface Response extends BackendResponse {
|
||||
sessions: ActiveSession[];
|
||||
}
|
||||
|
||||
export function useUserSessions() {
|
||||
return useQuery({
|
||||
queryKey: ['user-sessions'],
|
||||
queryFn: () => fetchUserSessions(),
|
||||
});
|
||||
}
|
||||
|
||||
function fetchUserSessions() {
|
||||
return apiClient
|
||||
.get<Response>(`user-sessions`)
|
||||
.then(response => response.data);
|
||||
}
|
||||
Reference in New Issue
Block a user