mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-18 01:22:43 +00:00
lint and logging pass prepared for in server auth from this end
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
// Set working directory to project root
|
// Set working directory to project root
|
||||||
import { dirname } from 'path';
|
import { dirname } from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import packageJSON from './../package.json' with { type: "json" };
|
import packageJSON from './../package.json' with { type: 'json' };
|
||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
process.chdir(`${__dirname}/..`);
|
process.chdir(`${__dirname}/..`);
|
||||||
@@ -47,7 +47,7 @@ const sanitizeBrew = (brew, accessType)=>{
|
|||||||
return brew;
|
return brew;
|
||||||
};
|
};
|
||||||
|
|
||||||
app.set('trust proxy', 1 /* number of proxies between user and server */)
|
app.set('trust proxy', 1 /* number of proxies between user and server */);
|
||||||
|
|
||||||
app.use('/', serveCompressedStaticAssets(`build`));
|
app.use('/', serveCompressedStaticAssets(`build`));
|
||||||
app.use(contentNegotiation);
|
app.use(contentNegotiation);
|
||||||
@@ -94,7 +94,6 @@ app.use((req, res, next)=>{
|
|||||||
console.log('passing through acc middleware, checking for cookies now: does cookies exist? ', !!req.cookies, ', ok, does the session cookie exist? ', !!req.cookies.nc_session);
|
console.log('passing through acc middleware, checking for cookies now: does cookies exist? ', !!req.cookies, ', ok, does the session cookie exist? ', !!req.cookies.nc_session);
|
||||||
if(req.cookies && req.cookies.nc_session){
|
if(req.cookies && req.cookies.nc_session){
|
||||||
try {
|
try {
|
||||||
console.log(`creating req.account equal to "${JSON.stringify(jwt.decode(req.cookies.nc_session, config.get('secret')))}"`);
|
|
||||||
req.account = jwt.decode(req.cookies.nc_session, config.get('secret'));
|
req.account = jwt.decode(req.cookies.nc_session, config.get('secret'));
|
||||||
//console.log("Just loaded up JWT from cookie:");
|
//console.log("Just loaded up JWT from cookie:");
|
||||||
//console.log(req.account);
|
//console.log(req.account);
|
||||||
@@ -312,7 +311,7 @@ app.get('/user/:username', async (req, res, next)=>{
|
|||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
brews.forEach(brew => brew.stubbed = true); //All brews from MongoDB are "stubbed"
|
brews.forEach((brew)=>brew.stubbed = true); //All brews from MongoDB are "stubbed"
|
||||||
|
|
||||||
if(ownAccount && req?.account?.googleId){
|
if(ownAccount && req?.account?.googleId){
|
||||||
const auth = await GoogleActions.authCheck(req.account, res);
|
const auth = await GoogleActions.authCheck(req.account, res);
|
||||||
@@ -355,7 +354,7 @@ app.get('/user/:username', async (req, res, next)=>{
|
|||||||
app.put('/api/user/rename', async (req, res)=>{
|
app.put('/api/user/rename', async (req, res)=>{
|
||||||
console.log(req.account);
|
console.log(req.account);
|
||||||
const { username, newUsername } = req.body;
|
const { username, newUsername } = req.body;
|
||||||
|
console.log(`is user ${req.account.username} equal to ${username}? ${req.account.username === username} ${req.account.username === username && 'then add the damn auth for renaming!'}`);
|
||||||
console.log('renaming');
|
console.log('renaming');
|
||||||
|
|
||||||
if(!username || !newUsername) {
|
if(!username || !newUsername) {
|
||||||
@@ -364,8 +363,7 @@ app.put('/api/user/rename', async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
const brews = await HomebrewModel.getByUser(username, true, ['authors']);
|
const brews = await HomebrewModel.getByUser(username, true, ['authors']);
|
||||||
const renamePromises = brews.map(async (brew)=>{
|
const renamePromises = brews.map(async (brew)=>{
|
||||||
const updatedAuthors = brew.authors.map((author) =>
|
const updatedAuthors = brew.authors.map((author)=>author === username ? newUsername : author
|
||||||
author === username ? newUsername : author
|
|
||||||
);
|
);
|
||||||
return HomebrewModel.updateOne(
|
return HomebrewModel.updateOne(
|
||||||
{ _id: brew._id },
|
{ _id: brew._id },
|
||||||
@@ -482,7 +480,7 @@ app.get('/account', asyncHandler(async (req, res, next)=>{
|
|||||||
let googleCount = [];
|
let googleCount = [];
|
||||||
if(req.account) {
|
if(req.account) {
|
||||||
if(req.account.googleId) {
|
if(req.account.googleId) {
|
||||||
auth = await GoogleActions.authCheck(req.account, res, false)
|
auth = await GoogleActions.authCheck(req.account, res, false);
|
||||||
|
|
||||||
googleCount = await GoogleActions.listGoogleBrews(auth)
|
googleCount = await GoogleActions.listGoogleBrews(auth)
|
||||||
.catch((err)=>{
|
.catch((err)=>{
|
||||||
|
|||||||
Reference in New Issue
Block a user