mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 22:27:16 +01:00
Implement redux.
This commit is contained in:
parent
9d8a2406e1
commit
5d4ff5cfa4
31 changed files with 341 additions and 85 deletions
|
|
@ -1,8 +1,9 @@
|
|||
import { parse } from 'cookie';
|
||||
import { verifySecureToken } from './crypto';
|
||||
import { AUTH_COOKIE_NAME } from './constants';
|
||||
|
||||
export default async req => {
|
||||
const token = parse(req.headers.cookie || '')['umami.auth'];
|
||||
export async function verifyAuthToken(req) {
|
||||
const token = parse(req.headers.cookie || '')[AUTH_COOKIE_NAME];
|
||||
|
||||
return verifySecureToken(token);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
1
lib/constants.js
Normal file
1
lib/constants.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
export const AUTH_COOKIE_NAME = 'umami.auth';
|
||||
|
|
@ -285,6 +285,8 @@ export const refFilter = data =>
|
|||
data.filter(({ x }) => x !== '' && !x.startsWith('/') && !x.startsWith('#'));
|
||||
|
||||
export const deviceFilter = data => {
|
||||
if (data.length === 0) return [];
|
||||
|
||||
const devices = data.reduce(
|
||||
(obj, { x, y }) => {
|
||||
const [width] = x.split('x');
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import cors from 'cors';
|
||||
import session from './session';
|
||||
import auth from './auth';
|
||||
import { verifySession } from './session';
|
||||
import { verifyAuthToken } from './auth';
|
||||
|
||||
export function use(middleware) {
|
||||
return (req, res) =>
|
||||
|
|
@ -18,7 +18,7 @@ export const useCors = use(cors());
|
|||
|
||||
export const useSession = use(async (req, res, next) => {
|
||||
try {
|
||||
req.session = await session(req);
|
||||
req.session = await verifySession(req);
|
||||
} catch {
|
||||
return res.status(400).end();
|
||||
}
|
||||
|
|
@ -27,7 +27,7 @@ export const useSession = use(async (req, res, next) => {
|
|||
|
||||
export const useAuth = use(async (req, res, next) => {
|
||||
try {
|
||||
req.auth = await auth(req);
|
||||
req.auth = await verifyAuthToken(req);
|
||||
} catch {
|
||||
return res.status(401).end();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { getWebsite, getSession, createSession } from 'lib/db';
|
|||
import { getCountry, getDevice, getIpAddress } from 'lib/request';
|
||||
import { uuid, isValidId, verifyToken } from 'lib/crypto';
|
||||
|
||||
export default async req => {
|
||||
export async function verifySession(req) {
|
||||
const { payload } = req.body;
|
||||
const { website: website_uuid, hostname, screen, language, session } = payload;
|
||||
|
||||
|
|
@ -51,4 +51,4 @@ export default async req => {
|
|||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue