fix(server): version CRM de backend/shared (suppression des roles)
deploy / deploy (push) Successful in 31s
deploy / deploy (push) Successful in 31s
This commit is contained in:
@@ -61,8 +61,6 @@ export interface SessionUser {
|
||||
email: string;
|
||||
first_name: string;
|
||||
last_name: string;
|
||||
role_slug: string;
|
||||
role_name: string;
|
||||
is_active: number;
|
||||
must_change_password: number;
|
||||
}
|
||||
@@ -106,12 +104,10 @@ export const createSession = async (
|
||||
export const resolveSession = async (db: Db, token: string): Promise<SessionUser | null> => {
|
||||
const row = await db.one<SessionUser & { last_seen_at: string }>(
|
||||
`SELECT u.id, u.email, u.first_name, u.last_name,
|
||||
r.slug AS role_slug, r.name AS role_name,
|
||||
u.is_active, u.must_change_password,
|
||||
s.last_seen_at
|
||||
FROM user_sessions s
|
||||
JOIN users u ON u.id = s.user_id
|
||||
JOIN roles r ON r.id = u.role_id
|
||||
WHERE s.token_hash = ?
|
||||
AND s.revoked_at IS NULL
|
||||
AND s.expires_at > UTC_TIMESTAMP()
|
||||
@@ -205,18 +201,7 @@ export const requireAuth = async (context: Context, next: Next): Promise<void> =
|
||||
await next();
|
||||
};
|
||||
|
||||
/** Le role est impose en base, jamais en entete, donc ni cacheable ni falsifiable. */
|
||||
export const requireRole =
|
||||
(...slugs: string[]) =>
|
||||
async (context: Context, next: Next): Promise<void> => {
|
||||
const user = context.get("user") as SessionUser | undefined;
|
||||
if (!user) throw AppError.unauthorized();
|
||||
if (!slugs.includes(user.role_slug)) {
|
||||
throw AppError.forbidden(`Action reservee au role : ${slugs.join(", ")}.`);
|
||||
}
|
||||
await next();
|
||||
};
|
||||
|
||||
/** Le role n'existe plus : tout compte authentifie a les memes droits. */
|
||||
export const currentUser = (context: Context): SessionUser => {
|
||||
const user = context.get("user") as SessionUser | undefined;
|
||||
if (!user) throw AppError.unauthorized();
|
||||
|
||||
@@ -24,7 +24,6 @@ export {
|
||||
isHttpsRequest,
|
||||
hashPassword,
|
||||
requireAuth,
|
||||
requireRole,
|
||||
purgeExpiredSessions,
|
||||
revokeSession,
|
||||
SESSION_COOKIE,
|
||||
|
||||
Reference in New Issue
Block a user