mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 12:47:13 +01:00
Use token authentication for API requests.
This commit is contained in:
parent
bff8806b61
commit
96bd7e5b47
34 changed files with 198 additions and 153 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import cors from 'cors';
|
||||
import { verifySession } from './session';
|
||||
import { verifyAuthToken } from './auth';
|
||||
import { getSession } from './session';
|
||||
import { getAuthToken } from './auth';
|
||||
import { unauthorized, badRequest, serverError } from './response';
|
||||
|
||||
export function use(middleware) {
|
||||
|
|
@ -21,7 +21,7 @@ export const useSession = use(async (req, res, next) => {
|
|||
let session;
|
||||
|
||||
try {
|
||||
session = await verifySession(req);
|
||||
session = await getSession(req);
|
||||
} catch (e) {
|
||||
return serverError(res, e.message);
|
||||
}
|
||||
|
|
@ -35,13 +35,7 @@ export const useSession = use(async (req, res, next) => {
|
|||
});
|
||||
|
||||
export const useAuth = use(async (req, res, next) => {
|
||||
let token;
|
||||
|
||||
try {
|
||||
token = await verifyAuthToken(req);
|
||||
} catch (e) {
|
||||
return serverError(res, e.message);
|
||||
}
|
||||
const token = await getAuthToken(req);
|
||||
|
||||
if (!token) {
|
||||
return unauthorized(res);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue