Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
Updated user get.
Mike Cao02c9e0115ef5
diff --git a/src/lib/middleware.ts b/src/lib/middleware.tsindex b54f6d3ac..a6da65c0d 100644--- a/src/lib/middleware.ts+++ b/src/lib/middleware.ts@@ -3,7 +3,7 @@ import debug from 'debug';import redis from '@umami/redis-client';import { getAuthToken, parseShareToken } from 'lib/auth';import { ROLES } from 'lib/constants';-import { isUuid, secret } from 'lib/crypto';+import { secret } from 'lib/crypto';import { findSession } from 'lib/session';import {badRequest,@@ -52,7 +52,7 @@ export const useAuth = createMiddleware(async (req, res, next) => {let user = null;const { userId, authKey, grant } = payload || {};- if (isUuid(userId)) {+ if (userId) {user = await getUserById(userId);} else if (redis.enabled && authKey) {const key = await redis.client.get(authKey);@@ -61,7 +61,7 @@ export const useAuth = createMiddleware(async (req, res, next) => {}if (process.env.NODE_ENV === 'development') {- log({ token, shareToken, payload, user, grant });+ log('useAuth:', { token, shareToken, payload, user, grant });}if (!user?.id && !shareToken) {diff --git a/src/queries/admin/user.ts b/src/queries/admin/user.tsindex b73199427..11f1c846e 100644--- a/src/queries/admin/user.ts+++ b/src/queries/admin/user.ts@@ -11,13 +11,17 @@ export interface GetUserOptions {}async function getUser(- where: Prisma.UserWhereInput | Prisma.UserWhereUniqueInput,+ where: Prisma.UserWhereUniqueInput,options: GetUserOptions = {},): Promise<User> {const { includePassword = false, showDeleted = false } = options;- return prisma.client.user.findFirst({- where: { ...where, ...(showDeleted ? {} : { deletedAt: null }) },+ if (showDeleted) {+ where.deletedAt = null;+ }++ return prisma.client.user.findUnique({+ where,select: {id: true,username: true,@@ -28,8 +32,8 @@ async function getUser(});}-export async function getUserById(userId: string, options: GetUserOptions = {}) {- return getUser({ id: userId }, options);+export async function getUserById(id: string, options: GetUserOptions = {}) {+ return getUser({ id }, options);}export async function getUserByUsername(username: string, options: GetUserOptions = {}) {