mirror of
https://github.com/umami-software/umami.git
synced 2026-02-09 07:07:17 +01:00
Refactored useApi usage.
This commit is contained in:
parent
561cde6e7e
commit
cad0b73e42
26 changed files with 67 additions and 85 deletions
18
lib/array.js
18
lib/array.js
|
|
@ -1,18 +0,0 @@
|
|||
export function chunk(arr, size) {
|
||||
const chunks = [];
|
||||
|
||||
let index = 0;
|
||||
while (index < arr.length) {
|
||||
chunks.push(arr.slice(index, size + index));
|
||||
index += size;
|
||||
}
|
||||
|
||||
return chunks;
|
||||
}
|
||||
|
||||
export function sortArrayByMap(arr, map = [], key) {
|
||||
if (!arr) return [];
|
||||
if (map.length === 0) return arr;
|
||||
|
||||
return map.map(id => arr.find(item => item[key] === id));
|
||||
}
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
import { getItem, setItem, removeItem } from 'next-basics';
|
||||
import { AUTH_TOKEN } from './constants';
|
||||
|
||||
export function getAuthToken() {
|
||||
export function getClientAuthToken() {
|
||||
return getItem(AUTH_TOKEN);
|
||||
}
|
||||
|
||||
export function setAuthToken(token) {
|
||||
export function setClientAuthToken(token) {
|
||||
setItem(AUTH_TOKEN, token);
|
||||
}
|
||||
|
||||
export function removeAuthToken() {
|
||||
export function removeClientAuthToken() {
|
||||
removeItem(AUTH_TOKEN);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ export const useSession = createMiddleware(async (req, res, next) => {
|
|||
return badRequest(res);
|
||||
}
|
||||
|
||||
req.session = session;
|
||||
(req as any).session = session;
|
||||
next();
|
||||
});
|
||||
|
||||
|
|
@ -50,6 +50,6 @@ export const useAuth = createMiddleware(async (req, res, next) => {
|
|||
user.isAdmin = user.role === ROLES.admin;
|
||||
}
|
||||
|
||||
req.auth = { user, token, shareToken, key };
|
||||
(req as any).auth = { user, token, shareToken, key };
|
||||
next();
|
||||
});
|
||||
|
|
@ -3,7 +3,7 @@ import { validate } from 'uuid';
|
|||
import { secret, uuid } from 'lib/crypto';
|
||||
import cache from 'lib/cache';
|
||||
import clickhouse from 'lib/clickhouse';
|
||||
import { getClientInfo, getJsonBody } from 'lib/request';
|
||||
import { getClientInfo, getJsonBody } from 'lib/detect';
|
||||
import { createSession, getSession, getWebsite } from 'queries';
|
||||
|
||||
export async function findSession(req) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue