set public next env vars from config

This commit is contained in:
Milo Schwartz
2024-10-12 21:23:12 -04:00
parent cf1de2253b
commit 61fca6a1f6
7 changed files with 69 additions and 33 deletions

View File

@@ -1,24 +1,36 @@
import { Request, Response, NextFunction } from 'express';
import { z } from 'zod';
import { db } from '@server/db';
import { users } from '@server/db/schema';
import { eq } from 'drizzle-orm';
import { Request, Response, NextFunction } from "express";
import { z } from "zod";
import { db } from "@server/db";
import { users } from "@server/db/schema";
import { eq } from "drizzle-orm";
import response from "@server/utils/response";
import HttpCode from '@server/types/HttpCode';
import createHttpError from 'http-errors';
import { ActionsEnum, checkUserActionPermission } from '@server/auth/actions';
import logger from '@server/logger';
import HttpCode from "@server/types/HttpCode";
import createHttpError from "http-errors";
import { ActionsEnum, checkUserActionPermission } from "@server/auth/actions";
import logger from "@server/logger";
export type GetUserResponse = {
email: string;
twoFactorEnabled: boolean;
emailVerified: boolean;
};
export async function getUser(req: Request, res: Response, next: NextFunction): Promise<any> {
export async function getUser(
req: Request,
res: Response,
next: NextFunction,
): Promise<any> {
try {
const userId = req.user?.id;
if (!userId) {
return next(createHttpError(HttpCode.UNAUTHORIZED, "User not found"));
return next(
createHttpError(HttpCode.UNAUTHORIZED, "User not found"),
);
}
const user = await db.select()
const user = await db
.select()
.from(users)
.where(eq(users.id, userId))
.limit(1);
@@ -27,16 +39,16 @@ export async function getUser(req: Request, res: Response, next: NextFunction):
return next(
createHttpError(
HttpCode.NOT_FOUND,
`User with ID ${userId} not found`
)
`User with ID ${userId} not found`,
),
);
}
return response(res, {
return response<GetUserResponse>(res, {
data: {
email: user[0].email,
twoFactorEnabled: user[0].twoFactorEnabled,
emailVerified: user[0].emailVerified
emailVerified: user[0].emailVerified,
},
success: true,
error: false,
@@ -45,6 +57,11 @@ export async function getUser(req: Request, res: Response, next: NextFunction):
});
} catch (error) {
logger.error(error);
return next(createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred..."));
return next(
createHttpError(
HttpCode.INTERNAL_SERVER_ERROR,
"An error occurred...",
),
);
}
}