sitcod3 commited on
Commit
8b499f7
·
verified ·
1 Parent(s): 73245db

Upload src/server/middleware/auth.ts with huggingface_hub

Browse files
Files changed (1) hide show
  1. src/server/middleware/auth.ts +8 -8
src/server/middleware/auth.ts CHANGED
@@ -15,7 +15,7 @@
15
  // LICENSE_ENFORCEMENT=true
16
  //
17
  // Frontend equivalent lives in the FortyDN website repo (src/lib/productApi.ts).
18
- // Ported from BRIDGE Modul-E (src/server/middleware/auth.ts) - same contract.
19
 
20
  import type { Request, Response, NextFunction } from "express";
21
  import { createRemoteJWKSet, jwtVerify } from "jose";
@@ -60,7 +60,7 @@ export async function verifySupabaseJwt(token: string): Promise<AuthClaims> {
60
  };
61
  }
62
 
63
- /** Modul-S is unlocked directly, via Validate+Send, or via Full Bridge. */
64
  const MODULS_GRANTS = new Set([
65
  "modul-s",
66
  "combo-validate-send",
@@ -70,7 +70,7 @@ const MODULS_GRANTS = new Set([
70
  export async function hasModulSLicense(userId: string): Promise<boolean> {
71
  const serviceKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
72
  if (!serviceKey) {
73
- console.warn("[auth] SUPABASE_SERVICE_ROLE_KEY not set - cannot check licenses.");
74
  return false;
75
  }
76
  const params = new URLSearchParams({
@@ -105,7 +105,7 @@ export function requireAuth(req: Request, res: Response, next: NextFunction) {
105
  void (async () => {
106
  const token = bearerToken(req);
107
  if (!token) {
108
- return res.status(401).json({ detail: "Missing bearer token - sign in first." });
109
  }
110
  try {
111
  const claims = await verifySupabaseJwt(token);
@@ -118,15 +118,15 @@ export function requireAuth(req: Request, res: Response, next: NextFunction) {
118
  }
119
 
120
  /**
121
- * Requires a valid JWT AND an active Modul-S license (direct, Validate+Send,
122
- * or Full Bridge). No-op while LICENSE_ENFORCEMENT is off.
123
  */
124
  export function requireModulSLicense(req: Request, res: Response, next: NextFunction) {
125
  if (!enforcementOn()) return next();
126
  void (async () => {
127
  const token = bearerToken(req);
128
  if (!token) {
129
- return res.status(401).json({ detail: "Missing bearer token - sign in first." });
130
  }
131
  try {
132
  const claims = await verifySupabaseJwt(token);
@@ -135,7 +135,7 @@ export function requireModulSLicense(req: Request, res: Response, next: NextFunc
135
  if (!ok) {
136
  return res
137
  .status(402)
138
- .json({ detail: "No active Modul-S license - see /pricing." });
139
  }
140
  return next();
141
  } catch {
 
15
  // LICENSE_ENFORCEMENT=true
16
  //
17
  // Frontend equivalent lives in the FortyDN website repo (src/lib/productApi.ts).
18
+ // Ported from BRIDGE Modul-X (src/server/middleware/auth.ts) — same contract.
19
 
20
  import type { Request, Response, NextFunction } from "express";
21
  import { createRemoteJWKSet, jwtVerify } from "jose";
 
60
  };
61
  }
62
 
63
+ /** Combos that unlock Modul-S (mirrors the website catalog). */
64
  const MODULS_GRANTS = new Set([
65
  "modul-s",
66
  "combo-validate-send",
 
70
  export async function hasModulSLicense(userId: string): Promise<boolean> {
71
  const serviceKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
72
  if (!serviceKey) {
73
+ console.warn("[auth] SUPABASE_SERVICE_ROLE_KEY not set — cannot check licenses.");
74
  return false;
75
  }
76
  const params = new URLSearchParams({
 
105
  void (async () => {
106
  const token = bearerToken(req);
107
  if (!token) {
108
+ return res.status(401).json({ detail: "Missing bearer token — sign in first." });
109
  }
110
  try {
111
  const claims = await verifySupabaseJwt(token);
 
118
  }
119
 
120
  /**
121
+ * Requires a valid JWT AND an active Modul-S license (direct or via combo).
122
+ * No-op while LICENSE_ENFORCEMENT is off.
123
  */
124
  export function requireModulSLicense(req: Request, res: Response, next: NextFunction) {
125
  if (!enforcementOn()) return next();
126
  void (async () => {
127
  const token = bearerToken(req);
128
  if (!token) {
129
+ return res.status(401).json({ detail: "Missing bearer token — sign in first." });
130
  }
131
  try {
132
  const claims = await verifySupabaseJwt(token);
 
135
  if (!ok) {
136
  return res
137
  .status(402)
138
+ .json({ detail: "No active Modul-S license — see /pricing." });
139
  }
140
  return next();
141
  } catch {