mirror of
https://github.com/thiloho/archtika.git
synced 2025-12-23 23:23:35 +01:00
Use util fetch for hook as well
This commit is contained in:
@@ -1,30 +1,25 @@
|
||||
import { redirect } from "@sveltejs/kit";
|
||||
import { API_BASE_PREFIX } from "$lib/server/utils";
|
||||
import type { User } from "$lib/db-schema";
|
||||
import { API_BASE_PREFIX, apiRequest } from "$lib/server/utils";
|
||||
|
||||
export const handle = async ({ event, resolve }) => {
|
||||
if (!event.url.pathname.startsWith("/api/")) {
|
||||
const userData = await event.fetch(`${API_BASE_PREFIX}/account`, {
|
||||
method: "GET",
|
||||
const userData = await apiRequest(event.fetch, `${API_BASE_PREFIX}/account`, "GET", {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${event.cookies.get("session_token")}`,
|
||||
Accept: "application/vnd.pgrst.object+json"
|
||||
}
|
||||
},
|
||||
returnData: true
|
||||
});
|
||||
|
||||
if (!userData.ok && !["/login", "/register"].includes(event.url.pathname)) {
|
||||
if (!userData.success && !["/login", "/register"].includes(event.url.pathname)) {
|
||||
throw redirect(303, "/login");
|
||||
}
|
||||
|
||||
if (userData.ok) {
|
||||
if (userData.success) {
|
||||
if (["/login", "/register"].includes(event.url.pathname)) {
|
||||
throw redirect(303, "/");
|
||||
}
|
||||
|
||||
const user: User = await userData.json();
|
||||
|
||||
event.locals.user = user;
|
||||
event.locals.user = userData.data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user