mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 12:47:13 +01:00
Updated redis logic.
This commit is contained in:
parent
39e7ceac06
commit
4d6ec631f7
9 changed files with 52 additions and 46 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import { z } from 'zod';
|
||||
import { checkPassword } from '@/lib/auth';
|
||||
import { createSecureToken } from '@/lib/jwt';
|
||||
import { redisEnabled } from '@umami/redis-client';
|
||||
import redis from '@/lib/redis';
|
||||
import { getUserByUsername } from '@/queries';
|
||||
import { json, unauthorized } from '@/lib/response';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
|
|
@ -29,15 +29,16 @@ export async function POST(request: Request) {
|
|||
return unauthorized();
|
||||
}
|
||||
|
||||
if (redisEnabled) {
|
||||
const token = await saveAuth({ userId: user.id });
|
||||
|
||||
return json({ token, user });
|
||||
}
|
||||
|
||||
const token = createSecureToken({ userId: user.id }, secret());
|
||||
const { id, role, createdAt } = user;
|
||||
|
||||
let token = null;
|
||||
|
||||
if (redis.enabled) {
|
||||
token = await saveAuth({ userId: id, role });
|
||||
} else {
|
||||
token = createSecureToken({ userId: user.id, role }, secret());
|
||||
}
|
||||
|
||||
return json({
|
||||
token,
|
||||
user: { id, username, role, createdAt, isAdmin: role === ROLES.admin },
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
import { getClient, redisEnabled } from '@umami/redis-client';
|
||||
import redis from '@/lib/redis';
|
||||
import { ok } from '@/lib/response';
|
||||
|
||||
export async function POST(request: Request) {
|
||||
if (redisEnabled) {
|
||||
const redis = getClient();
|
||||
|
||||
if (redis.enabled) {
|
||||
const token = request.headers.get('authorization')?.split(' ')?.[1];
|
||||
|
||||
await redis.del(token);
|
||||
await redis.client.del(token);
|
||||
}
|
||||
|
||||
return ok();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { redisEnabled } from '@umami/redis-client';
|
||||
import redis from '@/lib/redis';
|
||||
import { json } from '@/lib/response';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { saveAuth } from '@/lib/auth';
|
||||
|
|
@ -10,7 +10,7 @@ export async function POST(request: Request) {
|
|||
return error();
|
||||
}
|
||||
|
||||
if (redisEnabled) {
|
||||
if (redis.enabled) {
|
||||
const token = await saveAuth({ userId: auth.user.id }, 86400);
|
||||
|
||||
return json({ user: auth.user, token });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue