mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
Auth and session middleware.
This commit is contained in:
parent
590a70c2ff
commit
d81ee3932d
14 changed files with 142 additions and 73 deletions
|
|
@ -1,4 +1,6 @@
|
|||
import cors from 'cors';
|
||||
import session from './session';
|
||||
import auth from './auth';
|
||||
|
||||
export function use(middleware) {
|
||||
return (req, res) =>
|
||||
|
|
@ -13,3 +15,21 @@ export function use(middleware) {
|
|||
}
|
||||
|
||||
export const useCors = use(cors());
|
||||
|
||||
export const useSession = use(async (req, res, next) => {
|
||||
try {
|
||||
req.session = await session(req);
|
||||
} catch {
|
||||
return res.status(400).end();
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
export const useAuth = use(async (req, res, next) => {
|
||||
try {
|
||||
req.auth = await auth(req);
|
||||
} catch {
|
||||
return res.status(401).end();
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue