mirror of https://github.com/buster-so/buster.git
added env validation for server
This commit is contained in:
parent
21c76f268a
commit
28e704c53e
|
@ -1,7 +1,6 @@
|
||||||
import { dbPing } from '@buster/database';
|
import { dbPing } from '@buster/database';
|
||||||
import { Hono } from 'hono';
|
import { Hono } from 'hono';
|
||||||
import type { Context } from 'hono';
|
import type { Context } from 'hono';
|
||||||
|
|
||||||
interface HealthCheckResult {
|
interface HealthCheckResult {
|
||||||
status: 'healthy' | 'unhealthy' | 'degraded';
|
status: 'healthy' | 'unhealthy' | 'degraded';
|
||||||
timestamp: string;
|
timestamp: string;
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
import { Hono } from 'hono';
|
import { Hono } from 'hono';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
// Load environment variables from root .env file
|
||||||
|
import { loadRootEnv } from '@buster/env-utils';
|
||||||
|
loadRootEnv();
|
||||||
|
|
||||||
// Import custom middleware
|
// Import custom middleware
|
||||||
import { corsMiddleware } from './middleware/cors';
|
import { corsMiddleware } from './middleware/cors';
|
||||||
import { loggerMiddleware } from './middleware/logger';
|
import { loggerMiddleware } from './middleware/logger';
|
||||||
|
|
|
@ -2,14 +2,12 @@ import { getUser, getUserOrganizationId } from '@buster/database';
|
||||||
import type { Context, Next } from 'hono';
|
import type { Context, Next } from 'hono';
|
||||||
import { bearerAuth } from 'hono/bearer-auth';
|
import { bearerAuth } from 'hono/bearer-auth';
|
||||||
import { isOrganizationAdmin } from '../utils/admin';
|
import { isOrganizationAdmin } from '../utils/admin';
|
||||||
import { createSupabaseClient } from './supabase';
|
import { getSupabaseClient } from './supabase';
|
||||||
|
|
||||||
const supabase = createSupabaseClient();
|
|
||||||
|
|
||||||
export const requireAuth = bearerAuth({
|
export const requireAuth = bearerAuth({
|
||||||
verifyToken: async (token, c) => {
|
verifyToken: async (token, c) => {
|
||||||
try {
|
try {
|
||||||
const { data, error } = await supabase.auth.getUser(token); //usually takes about 3 - 7ms
|
const { data, error } = await getSupabaseClient().auth.getUser(token); //usually takes about 3 - 7ms
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
// Log specific auth errors to help with debugging
|
// Log specific auth errors to help with debugging
|
||||||
|
@ -73,7 +71,7 @@ export async function requireUser(c: Context, next: Next) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { data, error } = await supabase.auth.getUser(token);
|
const { data, error } = await getSupabaseClient().auth.getUser(token);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.warn('Token validation failed in requireUser:', {
|
console.warn('Token validation failed in requireUser:', {
|
||||||
|
|
|
@ -17,3 +17,12 @@ export const createSupabaseClient = () => {
|
||||||
|
|
||||||
return supabase;
|
return supabase;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let globalSupabase: ReturnType<typeof createSupabaseClient> | null = null;
|
||||||
|
|
||||||
|
export const getSupabaseClient = () => {
|
||||||
|
if (!globalSupabase) {
|
||||||
|
globalSupabase = createSupabaseClient();
|
||||||
|
}
|
||||||
|
return globalSupabase;
|
||||||
|
};
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
"@buster/vitest-config": "workspace:*",
|
"@buster/vitest-config": "workspace:*",
|
||||||
"@buster/web-tools": "workspace:*",
|
"@buster/web-tools": "workspace:*",
|
||||||
"@mastra/core": "catalog:",
|
"@mastra/core": "catalog:",
|
||||||
"@trigger.dev/sdk": "4.0.0-v4-beta.26",
|
"@trigger.dev/sdk": "4.0.0-v4-beta.27",
|
||||||
"ai": "catalog:",
|
"ai": "catalog:",
|
||||||
"braintrust": "catalog:",
|
"braintrust": "catalog:",
|
||||||
"vitest": "catalog:",
|
"vitest": "catalog:",
|
||||||
|
@ -38,6 +38,6 @@
|
||||||
"drizzle-orm": "catalog:"
|
"drizzle-orm": "catalog:"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@trigger.dev/build": "^4.0.0-v4-beta.26"
|
"@trigger.dev/build": "4.0.0-v4-beta.27"
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue