diff --git a/server/app.ts b/server/app.ts index d8c89f5..263a112 100644 --- a/server/app.ts +++ b/server/app.ts @@ -98,11 +98,13 @@ let sessionObject = { store: redisStore, secret: process.env.VITE_OPB_SERVER_SESSION_PASSWORD, resave: false, - saveUninitialized: true, + saveUninitialized: false, // Don't save empty sessions (better for authenticated apps) cookie: { httpOnly: true, secure: false, - maxAge: 300 * 1000 // 5 minutes in milliseconds + maxAge: process.env.VITE_SESSION_MAX_AGE + ? parseInt(process.env.VITE_SESSION_MAX_AGE) * 1000 + : 60 * 60 * 1000 // Default: 1 hour in milliseconds (value in env should be in seconds) } } if (app.get('env') === 'production') { diff --git a/server/controllers/RequestController.ts b/server/controllers/RequestController.ts index 00a121e..7cadd8a 100644 --- a/server/controllers/RequestController.ts +++ b/server/controllers/RequestController.ts @@ -74,6 +74,16 @@ export class OBPController { const data = request.body const oauthConfig = session['clientConfig'] + // Debug logging to diagnose authentication issues + console.log('RequestController.create - Debug Info:') + console.log(' Path:', path) + console.log(' Session exists:', !!session) + console.log(' Session keys:', session ? Object.keys(session) : 'N/A') + console.log(' clientConfig exists:', !!oauthConfig) + console.log(' oauth2 exists:', oauthConfig?.oauth2 ? 'YES' : 'NO') + console.log(' accessToken exists:', oauthConfig?.oauth2?.accessToken ? 'YES' : 'NO') + console.log(' oauth2_user exists:', session?.oauth2_user ? 'YES' : 'NO') + try { const result = await this.obpClientService.create(path, data, oauthConfig) return response.json(result) diff --git a/src/components/Preview.vue b/src/components/Preview.vue index ccae9dd..3bdfeb3 100644 --- a/src/components/Preview.vue +++ b/src/components/Preview.vue @@ -174,7 +174,10 @@ const submit = async (form: FormInstance, fn: () => void) => { } const highlightCode = (json) => { if (json.error) { - successResponseBody.value = json.error.message + // Display the full OBP error object with proper formatting + successResponseBody.value = hljs.lineNumbersValue( + hljs.highlightAuto(JSON.stringify(json.error, null, 4), ['JSON']).value + ) } else if (json) { successResponseBody.value = hljs.lineNumbersValue( hljs.highlightAuto(JSON.stringify(json, null, 4), ['JSON']).value diff --git a/src/obp/index.ts b/src/obp/index.ts index af9b396..b63395a 100644 --- a/src/obp/index.ts +++ b/src/obp/index.ts @@ -45,8 +45,12 @@ export async function isServerUp(): Promise { export async function get(path: string): Promise { try { return (await superagent.get(`/api/get?path=${path}`)).body - } catch (error) { + } catch (error: any) { console.log(error) + // Extract the full OBP error message from the response body + if (error.response && error.response.body) { + return { error: error.response.body } + } return { error } } } @@ -70,8 +74,12 @@ export async function create(path: string, body?: any): Promise { } } return (await request).body - } catch (error) { + } catch (error: any) { console.log(error) + // Extract the full OBP error message from the response body + if (error.response && error.response.body) { + return { error: error.response.body } + } return { error } } } @@ -95,8 +103,12 @@ export async function update(path: string, body?: any): Promise { } } return (await request).body - } catch (error) { + } catch (error: any) { console.log(error) + // Extract the full OBP error message from the response body + if (error.response && error.response.body) { + return { error: error.response.body } + } return { error } } } @@ -104,8 +116,12 @@ export async function update(path: string, body?: any): Promise { export async function discard(path: string): Promise { try { return (await superagent.delete(`/api/delete?path=${path}`)).body - } catch (error) { + } catch (error: any) { console.log(error) + // Extract the full OBP error message from the response body + if (error.response && error.response.body) { + return { error: error.response.body } + } return { error } } } @@ -113,8 +129,12 @@ export async function discard(path: string): Promise { export async function getCurrentUser(): Promise { try { return (await superagent.get(`/api/user/current`)).body - } catch (error) { + } catch (error: any) { console.log(error) + // Extract the full OBP error message from the response body + if (error.response && error.response.body) { + return { error: error.response.body } + } return { error } } }