removed useless server ts file
This commit is contained in:
@@ -1,93 +0,0 @@
|
||||
import { getUserController } from "@pkg/logic/domains/user/controller";
|
||||
import type { Session, User } from "@pkg/logic/domains/user/data";
|
||||
import { auth } from "@pkg/logic/domains/auth/config.base";
|
||||
import type { RequestHandler } from "@sveltejs/kit";
|
||||
import { env } from "$env/dynamic/private";
|
||||
import { api } from "$lib/api";
|
||||
|
||||
async function createContext(locals: App.Locals) {
|
||||
return { ...env, locals };
|
||||
}
|
||||
|
||||
async function getExecutionContext(sess: Session, user: User) {
|
||||
const flowId = crypto.randomUUID();
|
||||
return {
|
||||
flowId: flowId,
|
||||
userId: user.id,
|
||||
sessionId: sess.id,
|
||||
};
|
||||
}
|
||||
|
||||
async function getContext(headers: Headers) {
|
||||
const sess = await auth.api.getSession({ headers });
|
||||
if (!sess?.session) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
const fCtx = getExecutionContext(sess.session, sess.user);
|
||||
|
||||
return await getUserController()
|
||||
.getUserInfo(fCtx, sess.user.id)
|
||||
.match(
|
||||
(user) => {
|
||||
return {
|
||||
user: user,
|
||||
session: sess.session,
|
||||
fCtx: fCtx,
|
||||
};
|
||||
},
|
||||
(error) => {
|
||||
console.error(error);
|
||||
return false;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export const GET: RequestHandler = async ({ request }) => {
|
||||
const context = await getContext(request.headers);
|
||||
if (!context || typeof context === "boolean") {
|
||||
return new Response("Unauthorized", { status: 401 });
|
||||
}
|
||||
return api.fetch(request, await createContext(context));
|
||||
};
|
||||
|
||||
export const HEAD: RequestHandler = async ({ request }) => {
|
||||
const context = await getContext(request.headers);
|
||||
if (!context || typeof context === "boolean") {
|
||||
return new Response("Unauthorized", { status: 401 });
|
||||
}
|
||||
return api.fetch(request, await createContext(context));
|
||||
};
|
||||
|
||||
export const POST: RequestHandler = async ({ request }) => {
|
||||
const context = await getContext(request.headers);
|
||||
if (!context || typeof context === "boolean") {
|
||||
return new Response("Unauthorized", { status: 401 });
|
||||
}
|
||||
return api.fetch(request, await createContext(context));
|
||||
};
|
||||
|
||||
export const PUT: RequestHandler = async ({ request }) => {
|
||||
const context = await getContext(request.headers);
|
||||
if (!context || typeof context === "boolean") {
|
||||
return new Response("Unauthorized", { status: 401 });
|
||||
}
|
||||
return api.fetch(request, await createContext(context));
|
||||
};
|
||||
|
||||
export const DELETE: RequestHandler = async ({ request }) => {
|
||||
const context = await getContext(request.headers);
|
||||
if (!context || typeof context === "boolean") {
|
||||
return new Response("Unauthorized", { status: 401 });
|
||||
}
|
||||
return api.fetch(request, await createContext(context));
|
||||
};
|
||||
|
||||
export const OPTIONS: RequestHandler = async ({ request }) => {
|
||||
const context = await getContext(request.headers);
|
||||
if (!context || typeof context === "boolean") {
|
||||
return new Response("Unauthorized", { status: 401 });
|
||||
}
|
||||
return api.fetch(request, await createContext(context));
|
||||
};
|
||||
Reference in New Issue
Block a user