- Why doesn't setting the cookie in the auth middleware work?
- If
res.cookie("spotify", token)
works in spotifyAuthRouter, why not the middleware?- AH! It's because the connect call is made through href
- Could this possibly be the issue? (missing 'credentials: include')
- setting axios credentials flag
- setup prettier https://prettier.io/
- don't use nested promises
- multiple fixes, async / await probably preferred
- https://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html
- missing eslint on the server
- converting to npm workspace will fix this, more on that below
- remove redunant ternaries
a = b ? b : c
->a = b || c
a = b ? c : b
->a = b && c
- use optional chaining
a && a.b
->a?.b
- more consisent usage of object shorthand
{ a: a }
->{ a }
- use tailwind class sorting via prettier
- setup absolute imports
- shouldn't use nested ternaries in JSX
- this may be personal preference, but it's a rule I enforce
- Put things like environment variables in a single place and import them
// config.js
import dotenv from 'dotenv'
dotenv.config()
export default {
jwtSecret: process.env.JWT_SECRET
}
...
import config from './config'
config.jwtSecret
- why? possibly improved readabiliy, definitely improved debugging
- code execution will be linear, matching the way the function is written
// fail case last
if (a && b) {
return a > b;
}
return false;
// fail case first
if (!a || !b) return false;
return a > b;
- If it's a lot of variables you could write this as:
if ([a, b, c, d].some((x) => !x)) return false;
You can make a helper function for this:
function checkFalsey(...args) {
return args.some((x) => !x);
}
if (checkFalsey(a, b, c, d)) return false;
This is true for JSX too:
// fail case first
if (!loggedIn()) return <Component />;
return <App />;
- visual event & error handling
- currently I'm only seeing
console.log(error)
- ex: loading spinners, toast notifications
- currently I'm only seeing
- use
lsof
to check for open ports - don't re-use npm script names
- use different console.log titles to be more clear where issues are arising
// use numbers console.log(123, value); // use object shorthant console.log({ value });
- the repo currently has a hybrid workspace, make it a proper workspace
- server should have its own package json
- https://docs.npmjs.com/cli/v7/using-npm/workspaces
- switching to TypeScript
- know all your array methods
- lodash familiarity
- FP familiarity (Mostly Adequate Guide)
- Join a programming community group like Toronto JS (slack)
- cyclomatic complexity (aka nesting)
i recommend the nullish coalescing operator. it more accurately represents the intention of most cases. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing (careful refactoring code with it, because falsey values like 0 and '' will behave differently)