mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
* init map view * switching off 3d buildings when sattelite view is on * rename menu items * upgrading dependencies, adding provider to popups * adding screenshot for map view * fixing readme * next release version
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
/*
|
|
* Copyright (c) 2026 by Christian Kellner.
|
|
* Licensed under Apache-2.0 with Commons Clause and Attribution/Naming Clause
|
|
*/
|
|
|
|
import * as userStorage from '../services/storage/userStorage.js';
|
|
import cookieSession from 'cookie-session';
|
|
import { nanoid } from 'nanoid';
|
|
const unauthorized = (res) => {
|
|
return res.send(401);
|
|
};
|
|
const isUnauthorized = (req) => {
|
|
return req.session.currentUser == null;
|
|
};
|
|
const isAdmin = (req) => {
|
|
if (!isUnauthorized(req)) {
|
|
const user = userStorage.getUser(req.session.currentUser);
|
|
return user != null && user.isAdmin;
|
|
}
|
|
return false;
|
|
};
|
|
const authInterceptor = () => {
|
|
return (req, res, next) => {
|
|
if (isUnauthorized(req)) {
|
|
return unauthorized(res);
|
|
} else {
|
|
next();
|
|
}
|
|
};
|
|
};
|
|
const adminInterceptor = () => {
|
|
return (req, res, next) => {
|
|
if (!isAdmin(req)) {
|
|
return unauthorized(res);
|
|
} else {
|
|
next();
|
|
}
|
|
};
|
|
};
|
|
const cookieSession$0 = (userId) => {
|
|
return cookieSession({
|
|
name: 'fredy-admin-session',
|
|
keys: ['fredy', 'super', 'fancy', 'key', nanoid()],
|
|
userId,
|
|
maxAge: 2 * 60 * 60 * 1000, // 2 hours
|
|
});
|
|
};
|
|
export { cookieSession$0 as cookieSession };
|
|
export { adminInterceptor };
|
|
export { authInterceptor };
|
|
export { isUnauthorized };
|
|
export { isAdmin };
|