48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import type { BunextPageServerFn } from "@moduletrace/bunext/types";
|
|
import type { PagePropsType } from "../types";
|
|
import userAuth from "../functions/backend/auth/user-auth";
|
|
import grabHostDirnames from "../functions/backend/setup/grab-host-dir-names";
|
|
|
|
const server: BunextPageServerFn<PagePropsType> = async ({ req, url }) => {
|
|
const { user, user_types } = await userAuth({ req });
|
|
|
|
if (url.pathname.startsWith("/admin") && !user?.logged_in_status) {
|
|
return {
|
|
redirect: {
|
|
destination: "/auth/login",
|
|
permanent: false,
|
|
},
|
|
};
|
|
}
|
|
|
|
if (
|
|
url.pathname.startsWith("/auth") &&
|
|
!url.pathname.match(/logout/) &&
|
|
user?.logged_in_status
|
|
) {
|
|
return {
|
|
redirect: {
|
|
destination: "/admin",
|
|
permanent: false,
|
|
},
|
|
};
|
|
}
|
|
|
|
const main_host_dir_names = grabHostDirnames({});
|
|
|
|
return {
|
|
props: {
|
|
environment: process.env.NODE_ENV,
|
|
envs: {
|
|
R2_PUBLIC_DOMAIN: process.env.R2_PUBLIC_DOMAIN || "",
|
|
PAYSTACK_PUBLIC_KEY: process.env.PAYSTACK_PUBLIC_KEY || "",
|
|
},
|
|
user,
|
|
user_types,
|
|
main_host_dir_names,
|
|
},
|
|
};
|
|
};
|
|
|
|
export default server;
|