Protect the prober list using cookie

This commit is contained in:
ditatompel 2024-05-08 16:20:30 +07:00
parent c1ab301055
commit ffaa9b37d3
No known key found for this signature in database
GPG key ID: 31D3D06D77950979
2 changed files with 6 additions and 1 deletions

View file

@ -1,9 +1,14 @@
import { apiUri } from '$lib/utils/common';
import { goto } from '$app/navigation';
/** @param {import('@vincjo/datatables/remote/state')} state */
export const loadData = async (state) => {
const response = await fetch(apiUri(`/api/v1/prober?${getParams(state)}`));
const json = await response.json();
if (json.data === null) {
goto('/login');
return;
}
state.setTotalRows(json.data.total_rows ?? 0);
return json.data.items ?? [];
};

View file

@ -12,7 +12,7 @@ func AppRoute(app *fiber.App) {
func V1Api(app *fiber.App) {
v1 := app.Group("/api/v1")
v1.Get("/prober", Prober)
v1.Get("/prober", CookieProtected, Prober)
v1.Post("/prober", CookieProtected, Prober)
v1.Patch("/prober/:id", CookieProtected, Prober)
v1.Delete("/prober/:id", CookieProtected, Prober)