Updated redis calls.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import redis from '@umami/redis-client';
|
||||
import debug from 'debug';
|
||||
import { setAuthKey } from 'lib/auth';
|
||||
import { saveAuth } from 'lib/auth';
|
||||
import { secret } from 'lib/crypto';
|
||||
import { useValidate } from 'lib/middleware';
|
||||
import { NextApiRequestQueryBody, User } from 'lib/types';
|
||||
@@ -52,8 +52,8 @@ export default async (
|
||||
const user = await getUserByUsername(username, { includePassword: true });
|
||||
|
||||
if (user && checkPassword(password, user.password)) {
|
||||
if (redis) {
|
||||
const token = await setAuthKey(user);
|
||||
if (redis.enabled) {
|
||||
const token = await saveAuth({ userId: user.id });
|
||||
|
||||
return ok(res, { token, user });
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ export default async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
if (req.method === 'POST') {
|
||||
if (redis) {
|
||||
await redis.del(getAuthToken(req));
|
||||
if (redis.enabled) {
|
||||
await redis.client.del(getAuthToken(req));
|
||||
}
|
||||
|
||||
return ok(res);
|
||||
|
||||
@@ -3,13 +3,13 @@ import { useAuth } from 'lib/middleware';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { badRequest, ok } from 'next-basics';
|
||||
import redis from '@umami/redis-client';
|
||||
import { setAuthKey } from 'lib/auth';
|
||||
import { saveAuth } from 'lib/auth';
|
||||
|
||||
export default async (req: NextApiRequestAuth, res: NextApiResponse) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
if (redis && req.auth.user) {
|
||||
const token = await setAuthKey(req.auth.user, 86400);
|
||||
if (redis.enabled && req.auth.user) {
|
||||
const token = await saveAuth({ userId: req.auth.user.id }, 86400);
|
||||
|
||||
return ok(res, { user: req.auth.user, token });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user