From e38bcb3ebae48cf34752067fd2a1c6c9c7ca2f56 Mon Sep 17 00:00:00 2001 From: Isaac Liu Date: Sun, 17 Nov 2024 18:29:02 -0600 Subject: [PATCH] Fix authentication on backend For some reason the backend didn't run the authentication code in test mode, this was causing the linking to fail --- src/controllers/Dashboard.controller.ts | 4 +++- src/controllers/User.controller.ts | 2 +- src/middleware/validateAuth.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/controllers/Dashboard.controller.ts b/src/controllers/Dashboard.controller.ts index 60f1908..50b65a5 100644 --- a/src/controllers/Dashboard.controller.ts +++ b/src/controllers/Dashboard.controller.ts @@ -9,7 +9,9 @@ import type { Request, Response } from 'express'; * @param res - the response object */ export const getDashboardStats = async (req: Request, res: Response) => { - const base = new Airtable({ apiKey: process.env.AIRTABLE_API_KEY || '' }).base(process.env.AIRTABLE_BASE_ID || ''); + const base = new Airtable({ apiKey: process.env.AIRTABLE_API_KEY || '' }).base( + process.env.AIRTABLE_BASE_ID || '' + ); try { await base('Data Table') diff --git a/src/controllers/User.controller.ts b/src/controllers/User.controller.ts index 32f9176..ba188d0 100644 --- a/src/controllers/User.controller.ts +++ b/src/controllers/User.controller.ts @@ -92,7 +92,7 @@ export const linkUserToAirtableRecord = async ( return res.status(400).send('Airtable ID is required'); } - if (process.env.ENVIRONMENT !== 'test') { + if (true /*process.env.ENVIRONMENT !== 'test'*/) { try { await clerkClient.users.updateUserMetadata(req.auth.userId || '', { publicMetadata: { diff --git a/src/middleware/validateAuth.ts b/src/middleware/validateAuth.ts index 2ecf7d9..f9e46e9 100644 --- a/src/middleware/validateAuth.ts +++ b/src/middleware/validateAuth.ts @@ -21,7 +21,7 @@ const validateAuth = ( next: NextFunction ) => { // If the environment is not test, use ClerkExpressWithAuth to validate the user's session - if (process.env.ENVIRONMENT !== 'test') { + if (true /*process.env.ENVIRONMENT !== 'test'*/) { // Use ClerkExpressWithAuth to validate the user's session then call next() if the user is authenticated ClerkExpressWithAuth({})(req, res, async () => { if (req.auth.sessionId && req.auth.userId) {