major ui tweaks and refactoring

This commit is contained in:
Milo Schwartz
2025-01-04 20:22:01 -05:00
parent 51bf5c1408
commit 64158a823b
91 changed files with 1791 additions and 1246 deletions

View File

@@ -1,8 +1,11 @@
import { cookies } from "next/headers";
import { pullEnv } from "../pullEnv";
export async function authCookieHeader() {
const env = pullEnv();
const allCookies = await cookies();
const cookieName = process.env.SESSION_COOKIE_NAME!;
const cookieName = env.server.sessionCookieName;
const sessionId = allCookies.get(cookieName)?.value ?? null;
return {
headers: {

View File

@@ -1,9 +1,9 @@
import { env } from "@app/lib/types/env";
import { Env } from "@app/lib/types/env";
import axios, { AxiosInstance } from "axios";
let apiInstance: AxiosInstance | null = null;
export function createApiClient({ env }: { env: env }): AxiosInstance {
export function createApiClient({ env }: { env: Env }): AxiosInstance {
if (apiInstance) {
return apiInstance;
}
@@ -16,9 +16,9 @@ export function createApiClient({ env }: { env: env }): AxiosInstance {
let baseURL;
const suffix = "api/v1";
if (window.location.port === env.NEXT_PORT) {
if (window.location.port === env.server.nextPort) {
// this means the user is addressing the server directly
baseURL = `${window.location.protocol}//${window.location.hostname}:${env.SERVER_EXTERNAL_PORT}/${suffix}`;
baseURL = `${window.location.protocol}//${window.location.hostname}:${env.server.externalPort}/${suffix}`;
axios.defaults.withCredentials = true;
} else {
// user is accessing through a proxy

View File

@@ -2,12 +2,15 @@ import { internal } from "@app/lib/api";
import { authCookieHeader } from "@app/lib/api/cookies";
import { GetUserResponse } from "@server/routers/user";
import { AxiosResponse } from "axios";
import { pullEnv } from "../pullEnv";
export async function verifySession({
skipCheckVerifyEmail,
}: {
skipCheckVerifyEmail?: boolean;
} = {}): Promise<GetUserResponse | null> {
const env = pullEnv();
try {
const res = await internal.get<AxiosResponse<GetUserResponse>>(
"/user",
@@ -23,7 +26,7 @@ export async function verifySession({
if (
!skipCheckVerifyEmail &&
!user.emailVerified &&
process.env.FLAGS_EMAIL_VERIFICATION_REQUIRED == "true"
env.flags.emailVerificationRequired
) {
return null;
}

31
src/lib/pullEnv.ts Normal file
View File

@@ -0,0 +1,31 @@
import { Env } from "./types/env";
export function pullEnv(): Env {
return {
server: {
nextPort: process.env.NEXT_PORT as string,
externalPort: process.env.SERVER_EXTERNAL_PORT as string,
sessionCookieName: process.env.SESSION_COOKIE_NAME as string,
resourceSessionCookieName: process.env.RESOURCE_SESSION_COOKIE_NAME as string
},
app: {
environment: process.env.ENVIRONMENT as string,
version: process.env.APP_VERSION as string
},
email: {
emailEnabled: process.env.EMAIL_ENABLED === "true" ? true : false
},
flags: {
disableUserCreateOrg:
process.env.DISABLE_USER_CREATE_ORG === "true" ? true : false,
disableSignupWithoutInvite:
process.env.DISABLE_SIGNUP_WITHOUT_INVITE === "true"
? true
: false,
emailVerificationRequired:
process.env.FLAGS_EMAIL_VERIFICATION_REQUIRED === "true"
? true
: false
}
};
}

View File

@@ -1,8 +1,20 @@
export type env = {
SERVER_EXTERNAL_PORT: string;
NEXT_PORT: string;
ENVIRONMENT: string;
EMAIL_ENABLED: string;
DISABLE_SIGNUP_WITHOUT_INVITE?: string;
DISABLE_USER_CREATE_ORG?: string;
export type Env = {
app: {
environment: string;
version: string;
},
server: {
externalPort: string;
nextPort: string;
sessionCookieName: string;
resourceSessionCookieName: string;
},
email: {
emailEnabled: boolean;
},
flags: {
disableSignupWithoutInvite: boolean;
disableUserCreateOrg: boolean;
emailVerificationRequired: boolean;
}
};