mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-09 04:06:36 +00:00
set public next env vars from config
This commit is contained in:
@@ -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...",
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user