Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alphonso's feedback #44

Open
camelPhonso opened this issue Oct 4, 2023 · 0 comments
Open

Alphonso's feedback #44

camelPhonso opened this issue Oct 4, 2023 · 0 comments

Comments

@camelPhonso
Copy link

Absolutely love the concept!! Your codebase looks really neat, and I was particularly a fan of how far you streamlined processes. For example:

function users(req, res, isWizard) {
    console.log(!isWizard)
    const title = 'PactPortal';
    const users = getUserList(isWizard ? 0 : 1); // defining your query through this simple boolean is super readable and re-usable
    const content = /*html*/ `
    <div class="banner">
    <div>
        <a href="/user"><button class="button">Profile</button></a>
        <a href="/log-out"><button class="button">Log Out</button></a>
    </div>
        ${users.map(user => createPost(user))} // exactly the same line of code for either result! I love it <3
    </div>
`
    return layout({ title, content });
}

Be careful with cleanups though. This is a tiny example, but ghost code like this creeps up and leads to overload and confusion:

router.post('/', (req, res) => {
    const { username, password, imageURL, isWizard, bio } = req.body;
    if (!username || !password) {
        res.status(400).send('Bad input');
    } else {
        bcrypt.hash(password, 12).then((hash) => {
            const user = createUser(username, hash, imageURL, isWizard, bio);
            const session_id = createSession(user.id);
            res.cookie('sid', session_id, {
                signed: true,
                maxAge: 1000 * 60 * 60 * 24 * 7,
                sameSite: 'lax',
                httpOnly: true,
            });
            // if (user.isWizard) {
            //     res.redirect(`/demons`);
            // } else {
            //     res.redirect(`/wizards`);
            // }

            res.redirect('/');
        });
    }
});

If something is commented out by the time you're ready to push just remove it.

Nice simple fix here, where you were struggling for a bit in the day:

function deleteUser(id) {
  console.log(`deleting user: ${id}`); // console.logs are dirty and I hate them though
  removeSessionByUserId(id);
  return delete_user.run({ id });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant