Code Snippet Library

Searchable snippets for the parts you build over and over.

Browse frontend-friendly examples for auth, API work, CRUD flows, webhooks, and reusable UI components. Everything is loaded from a local JSON file, so the experience stays fast and fully frontend-only.

Included

7

snippet starters

5

core categories

1 click

copy to clipboard

Selected snippet

Express JWT Guard

Protect private routes by validating the bearer token and attaching the decoded user to the request.

expressjwtmiddleware
javascript
1import jwt from "jsonwebtoken";
2 
3export const requireAuth = (req, res, next) => {
4 const authHeader = req.headers.authorization;
5 
6 if (!authHeader?.startsWith("Bearer ")) {
7 return res.status(401).json({ message: "Missing access token" });
8 }
9 
10 const token = authHeader.split(" ")[1];
11 
12 try {
13 req.user = jwt.verify(token, process.env.JWT_SECRET);
14 next();
15 } catch (error) {
16 return res.status(401).json({ message: "Invalid or expired token" });
17 }
18};