From c9947d7f91a0fea09d7c506fbcebc13302e2581a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Wed, 28 Aug 2024 20:42:53 +0200 Subject: [PATCH 1/5] handle invalid account in account page, redirect to home --- server/app.js | 1 + 1 file changed, 1 insertion(+) diff --git a/server/app.js b/server/app.js index 9afc9f270..cc407a20a 100644 --- a/server/app.js +++ b/server/app.js @@ -358,6 +358,7 @@ app.get('/share/:id', asyncHandler(getBrew('share')), asyncHandler(async (req, r //Account Page app.get('/account', asyncHandler(async (req, res, next)=>{ + if(!req.account) return res.redirect('/'); const data = {}; data.title = 'Account Information Page'; From 6436e62ec0df5f99e435d2eeca0d3e73adf59452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Wed, 28 Aug 2024 21:10:28 +0200 Subject: [PATCH 2/5] set up error page --- client/homebrew/pages/errorPage/errors/errorIndex.js | 11 +++++++++++ server/app.js | 10 +++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.js b/client/homebrew/pages/errorPage/errors/errorIndex.js index 7bf2caae1..770e8a090 100644 --- a/client/homebrew/pages/errorPage/errors/errorIndex.js +++ b/client/homebrew/pages/errorPage/errors/errorIndex.js @@ -2,6 +2,9 @@ const dedent = require('dedent-tabs').default; const loginUrl = 'https://www.naturalcrit.com/login'; +//001-050 : Brew errors +//050-100 : Other pages errors + const errorIndex = (props)=>{ return { // Default catch all @@ -149,6 +152,14 @@ const errorIndex = (props)=>{ **Brew ID:** ${props.brew.brewId}`, + //account page when account is not defined + '50' : dedent` + ## You are not signed in + + You are trying to access the account page. This page can only be accessed if you are signed in an account. + + Please login or signup at our [login page](https://www.naturalcrit.com/login?redirect=https://homebrewery.naturalcrit.com/account) `, + // Brew locked by Administrators error '100' : dedent` ## This brew has been locked. diff --git a/server/app.js b/server/app.js index cc407a20a..6829d9732 100644 --- a/server/app.js +++ b/server/app.js @@ -358,10 +358,18 @@ app.get('/share/:id', asyncHandler(getBrew('share')), asyncHandler(async (req, r //Account Page app.get('/account', asyncHandler(async (req, res, next)=>{ - if(!req.account) return res.redirect('/'); const data = {}; data.title = 'Account Information Page'; + if(!req.account) { + res.set('WWW-Authenticate', 'Bearer realm="Authorization Required"'); + const error = new Error('No valid account'); + error.status = 401; + error.HBErrorCode = '50'; + error.page = data.title; + return next(error); + }; + let auth; let googleCount = []; if(req.account) { From e8aceac133a99145ec808cc2e34306c9b88cc73d Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Wed, 28 Aug 2024 15:21:43 -0400 Subject: [PATCH 3/5] Move check for account up a little --- server/app.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/server/app.js b/server/app.js index 6829d9732..ec5275a3b 100644 --- a/server/app.js +++ b/server/app.js @@ -358,17 +358,17 @@ app.get('/share/:id', asyncHandler(getBrew('share')), asyncHandler(async (req, r //Account Page app.get('/account', asyncHandler(async (req, res, next)=>{ - const data = {}; - data.title = 'Account Information Page'; - if(!req.account) { res.set('WWW-Authenticate', 'Bearer realm="Authorization Required"'); - const error = new Error('No valid account'); - error.status = 401; - error.HBErrorCode = '50'; + const error = new Error('No valid account'); + error.status = 401; + error.HBErrorCode = '50'; error.page = data.title; - return next(error); + return next(error); }; + + const data = {}; + data.title = 'Account Information Page'; let auth; let googleCount = []; From 8423c48fd1ff2f0b9808d126d2b006fd2a593d41 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Wed, 28 Aug 2024 15:24:50 -0400 Subject: [PATCH 4/5] Slight rewording and add a period --- client/homebrew/pages/errorPage/errors/errorIndex.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.js b/client/homebrew/pages/errorPage/errors/errorIndex.js index 770e8a090..957991ad6 100644 --- a/client/homebrew/pages/errorPage/errors/errorIndex.js +++ b/client/homebrew/pages/errorPage/errors/errorIndex.js @@ -156,9 +156,9 @@ const errorIndex = (props)=>{ '50' : dedent` ## You are not signed in - You are trying to access the account page. This page can only be accessed if you are signed in an account. + You are trying to access the account page, but are not signed in to an account. - Please login or signup at our [login page](https://www.naturalcrit.com/login?redirect=https://homebrewery.naturalcrit.com/account) `, + Please login or signup at our [login page](https://www.naturalcrit.com/login?redirect=https://homebrewery.naturalcrit.com/account).`, // Brew locked by Administrators error '100' : dedent` @@ -174,4 +174,4 @@ const errorIndex = (props)=>{ }; }; -module.exports = errorIndex; \ No newline at end of file +module.exports = errorIndex; From a124bd86571f9ec47d238e056bbd023686e24406 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Wed, 28 Aug 2024 16:59:22 -0400 Subject: [PATCH 5/5] I'm dumb. --- server/app.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/app.js b/server/app.js index ec5275a3b..90d14aa5b 100644 --- a/server/app.js +++ b/server/app.js @@ -358,6 +358,9 @@ app.get('/share/:id', asyncHandler(getBrew('share')), asyncHandler(async (req, r //Account Page app.get('/account', asyncHandler(async (req, res, next)=>{ + const data = {}; + data.title = 'Account Information Page'; + if(!req.account) { res.set('WWW-Authenticate', 'Bearer realm="Authorization Required"'); const error = new Error('No valid account'); @@ -366,9 +369,6 @@ app.get('/account', asyncHandler(async (req, res, next)=>{ error.page = data.title; return next(error); }; - - const data = {}; - data.title = 'Account Information Page'; let auth; let googleCount = [];