add fetch users data, add loagout endpoints
This commit is contained in:
+16
-3
@@ -112,16 +112,29 @@ export async function authorization(
|
||||
|
||||
export async function logout() {
|
||||
const token = await getSessionData('token');
|
||||
console.log('logout');
|
||||
|
||||
try {
|
||||
await fetch(`${API_BASE_URL}/v1/api/auth/logout`, {
|
||||
const response = await fetch(`${API_BASE_URL}/api/admin`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
version: 1,
|
||||
msg_id: 100,
|
||||
token: token,
|
||||
message_body: {
|
||||
action: "logout"
|
||||
}
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
let parsed = await response.json();
|
||||
console.log(parsed);
|
||||
}
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
'use server'
|
||||
|
||||
import { redirect } from 'next/navigation';
|
||||
import { createSession, deleteSession, getSessionData, updateSession } from '@/app/actions/session';
|
||||
import { loginFormSchema, API_BASE_URL } from '@/app/actions/definitions';
|
||||
|
||||
export async function fetchUsesData(page: number, size: number) {
|
||||
const token = await getSessionData('token');
|
||||
console.log('fetchUsesData');
|
||||
|
||||
try {
|
||||
const response = await fetch(`${API_BASE_URL}/api/admin/get-users`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
version: 1,
|
||||
msg_id: 30014,
|
||||
message_body: {
|
||||
/* token: token, */
|
||||
action: 'getAllWithPagination',
|
||||
page: page,
|
||||
size: size
|
||||
}
|
||||
}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
console.log(response);
|
||||
|
||||
if (response.ok) {
|
||||
const parsed = await response.json();
|
||||
|
||||
if (parsed.message_code === 0) {
|
||||
return parsed.message_body;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
} else {
|
||||
throw new Error(`${response.status}`);
|
||||
}
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user