delete obsolote utils.js
This commit is contained in:
@@ -1,6 +1,58 @@
|
||||
import { BASE_API_URI } from "$lib/utils/constants";
|
||||
import { refreshCookie } from "$lib/utils/helpers";
|
||||
import { redirect } from "@sveltejs/kit";
|
||||
import { library } from "$lib/stores/library";
|
||||
/** @type {import('./$types').LayoutServerLoad} */
|
||||
export async function load({ locals }) {
|
||||
export async function load({ locals, cookies }) {
|
||||
const jwt = cookies.get("jwt");
|
||||
try {
|
||||
// Fetch subscriptions, and licence categories in parallel
|
||||
const [subscriptionsResponse, licenceCategoriesResponse] =
|
||||
await Promise.all([
|
||||
fetch(`${BASE_API_URI}/backend/membership/subscriptions`, {
|
||||
credentials: "include",
|
||||
headers: { Cookie: `jwt=${jwt}` },
|
||||
}),
|
||||
fetch(`${BASE_API_URI}/backend/licence/categories`, {
|
||||
credentials: "include",
|
||||
headers: { Cookie: `jwt=${jwt}` },
|
||||
}),
|
||||
]);
|
||||
|
||||
// Check if any of the responses are not ok
|
||||
if (!subscriptionsResponse.ok || !licenceCategoriesResponse.ok) {
|
||||
cookies.delete("jwt", { path: "/" });
|
||||
throw redirect(302, "/");
|
||||
}
|
||||
|
||||
// Parse the JSON responses
|
||||
const [subscriptionsData, licence_categoriesData] = await Promise.all([
|
||||
subscriptionsResponse.json(),
|
||||
licenceCategoriesResponse.json(),
|
||||
]);
|
||||
// Check if the server sent a new token
|
||||
const newToken =
|
||||
subscriptionsResponse.headers.get("Set-Cookie") == null
|
||||
? licenceCategoriesResponse.headers.get("Set-Cookie")
|
||||
: subscriptionsResponse.headers.get("Set-Cookie");
|
||||
|
||||
refreshCookie(newToken, null);
|
||||
|
||||
return {
|
||||
user: locals.user,
|
||||
licence_categories: licence_categoriesData.licence_categories,
|
||||
subscriptions: subscriptionsData.subscriptions,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error fetching data:", error);
|
||||
// In case of any error, clear the JWT cookie
|
||||
cookies.delete("jwt", { path: "/" });
|
||||
//throw redirect(302, "/");
|
||||
}
|
||||
|
||||
return {
|
||||
user: locals.user,
|
||||
licence_categories: [],
|
||||
subscriptions: [],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
<script>
|
||||
import SmallLoader from "$lib/components/SmallLoader.svelte";
|
||||
import Modal from "$lib/components/Modal.svelte";
|
||||
import { onMount } from "svelte";
|
||||
import { applyAction, enhance } from "$app/forms";
|
||||
import { page } from "$app/stores";
|
||||
import { receive, send } from "$lib/utils/helpers";
|
||||
import { t } from "svelte-i18n";
|
||||
import { fly } from "svelte/transition";
|
||||
import UserEditForm from "$lib/components/UserEditForm.svelte";
|
||||
import { onMount } from "svelte";
|
||||
import { page } from "$app/stores";
|
||||
import { t } from "svelte-i18n";
|
||||
import { library } from "$lib/stores/library";
|
||||
|
||||
/** @type {import('./$types').ActionData} */
|
||||
export let form;
|
||||
|
||||
$: ({ user, subscriptions, licence_categories } = $page.data);
|
||||
$: user = $page.data.user;
|
||||
|
||||
$: ({ licence_categories, subscriptions } = $library);
|
||||
|
||||
let showModal = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user