Skip to content

Instantly share code, notes, and snippets.

View EnriqueDev's full-sized avatar

Enrique Martín García EnriqueDev

View GitHub Profile
@joshnuss
joshnuss / app.js
Last active October 20, 2024 14:03
Express.js role-based permissions middleware
// the main app file
import express from "express";
import loadDb from "./loadDb"; // dummy middleware to load db (sets request.db)
import authenticate from "./authentication"; // middleware for doing authentication
import permit from "./authorization"; // middleware for checking if user's role is permitted to make request
const app = express(),
api = express.Router();
// first middleware will setup db connection
@mkjiau
mkjiau / axios-interceptors-refresh-token.js
Last active October 5, 2024 12:38
Axios interceptors for token refreshing and more than 2 async requests available
let isRefreshing = false;
let refreshSubscribers = [];
const instance = axios.create({
baseURL: Config.API_URL,
});
instance.interceptors.response.use(response => {
return response;
}, error => {