rename cookieJwtAuth to extractTokenFromCookie
This commit is contained in:
+2
-2
@@ -9,7 +9,7 @@ import {RestAuth} from "./rest/auth";
|
||||
import {config} from "./config";
|
||||
import cookieParser from 'cookie-parser';
|
||||
import {authLimiter, spotifyLimiter} from "./rest/middleware/rateLimit";
|
||||
import {cookieJwtAuth} from "./rest/middleware/cookieAuth";
|
||||
import {extractTokenFromCookie} from "./rest/middleware/extractTokenFromCookie ";
|
||||
import {UserService} from "./db/services/db/UserService";
|
||||
import {randomUUID} from "crypto";
|
||||
import {JwtAuthenticator} from "./utils/jwtAuthenticator";
|
||||
@@ -60,7 +60,7 @@ export async function startServer(jwtSecret: string) {
|
||||
|
||||
app.use("/api/auth", authLimiter, auth.createRouter());
|
||||
|
||||
app.use(cookieJwtAuth);
|
||||
app.use(extractTokenFromCookie);
|
||||
app.use("/api/spotify", _authenticateJwt, spotifyLimiter, spotify.createRouter());
|
||||
app.use("/api/websocket", _authenticateJwt, restWebSocket.createRouter());
|
||||
app.use("/api/user", _authenticateJwt, restUser.createRouter());
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
|
||||
export const cookieJwtAuth = (req: Request, res: Response, next: NextFunction) => {
|
||||
export const extractTokenFromCookie = (req: Request, res: Response, next: NextFunction) => {
|
||||
if (req.headers.authorization) {
|
||||
return next();
|
||||
}
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
import {cookieJwtAuth} from "../../../src/rest/middleware/cookieAuth";
|
||||
import {extractTokenFromCookie} from "../../../src/rest/middleware/extractTokenFromCookie";
|
||||
|
||||
describe("cookieJwtAuth Middleware", () => {
|
||||
it("should do nothing if Authorization header already exists", () => {
|
||||
@@ -15,7 +15,7 @@ describe("cookieJwtAuth Middleware", () => {
|
||||
const res = {} as Response;
|
||||
const next = vi.fn() as NextFunction;
|
||||
|
||||
cookieJwtAuth(req, res, next);
|
||||
extractTokenFromCookie(req, res, next);
|
||||
|
||||
expect(req.headers.authorization).toBe("Bearer existing-token");
|
||||
expect(next).toHaveBeenCalledOnce();
|
||||
@@ -31,7 +31,7 @@ describe("cookieJwtAuth Middleware", () => {
|
||||
const res = {} as Response;
|
||||
const next = vi.fn() as NextFunction;
|
||||
|
||||
cookieJwtAuth(req, res, next);
|
||||
extractTokenFromCookie(req, res, next);
|
||||
|
||||
expect(req.headers.authorization).toBe("Bearer my-secret-cookie-token");
|
||||
expect(next).toHaveBeenCalledOnce();
|
||||
@@ -45,7 +45,7 @@ describe("cookieJwtAuth Middleware", () => {
|
||||
const res = {} as Response;
|
||||
const next = vi.fn() as NextFunction;
|
||||
|
||||
cookieJwtAuth(req, res, next);
|
||||
extractTokenFromCookie(req, res, next);
|
||||
|
||||
expect(req.headers.authorization).toBeUndefined();
|
||||
expect(next).toHaveBeenCalledOnce();
|
||||
Reference in New Issue
Block a user