fix dashboard premium tables

This commit is contained in:
Emily
2025-04-05 16:32:38 +02:00
parent 70c15238a0
commit 10d4a9f1bc
24 changed files with 341 additions and 370 deletions

View File

@@ -4,6 +4,7 @@ import { UserModel } from "@schema/UserSchema";
import { ADMIN_EMAILS } from '@data/ADMINS';
import type { H3Event, EventHandlerRequest } from 'h3';
import { PremiumModel } from "~/shared/schema/PremiumSchema";
export type AuthContextLogged = {
id: string,
@@ -30,7 +31,7 @@ async function authorizationMiddleware(event: H3Event<EventHandlerRequest>) {
} else {
const [type, token] = authorization.split(' ');
const valid = readUserJwt(token);
if (!valid) return event.context.auth = { logged: false }
@@ -38,22 +39,28 @@ async function authorizationMiddleware(event: H3Event<EventHandlerRequest>) {
if (!user) return event.context.auth = { logged: false };
const roles: string[] = [];
if (ADMIN_EMAILS.includes(user.email)) {
roles.push('ADMIN');
}
const premium = await PremiumModel.findOne({ user_id: user.id });
if ((premium?.premium_type || 0) > 0) {
roles.push('PREMIUM');
}
const authContext: AuthContext = {
logged: true,
user: {
email: user.email,
name: user.name,
picture: user.picture || `https://robohash.org/${user.email}?set=set4`,
roles
roles,
},
id: user._id.toString()
}
event.context.auth = authContext;
}