mirror of
https://github.com/20kaushik02/spotify-manager.git
synced 2025-12-06 12:54:07 +00:00
- moved to typescript - axios rate limitmodule is busted, removed for now, do something else for that - sequelize-typescript - dotenv, not dotenv-flow - removed playlist details route types for API ton of minor fixes and improvements
32 lines
986 B
TypeScript
32 lines
986 B
TypeScript
import type { AxiosRequestHeaders } from "axios";
|
|
import type { RequestHandler } from "express";
|
|
|
|
import { sessionName } from "../constants.ts";
|
|
|
|
import curriedLogger from "../utils/logger.ts";
|
|
const logger = curriedLogger(import.meta.filename);
|
|
|
|
export const isAuthenticated: RequestHandler = (req, res, next) => {
|
|
if (req.session.accessToken) {
|
|
req.session.authHeaders = {
|
|
Authorization: `Bearer ${req.session.accessToken}`,
|
|
} as AxiosRequestHeaders;
|
|
next();
|
|
} else {
|
|
const delSession = req.session.destroy((error) => {
|
|
if (Object.keys(error).length) {
|
|
res.status(500).send({ message: "Internal Server Error" });
|
|
logger.error("session.destroy", { error });
|
|
return null;
|
|
} else {
|
|
res.clearCookie(sessionName);
|
|
res.status(401).send({ message: "Unauthorized" });
|
|
logger.debug("Session invalid, destroyed.", {
|
|
sessionID: delSession.id,
|
|
});
|
|
return null;
|
|
}
|
|
});
|
|
}
|
|
};
|