refactor(middleware-jwt): verifyPayload$ as second argument
MODIFY
packages/middleware-jwt/src/jwt.middleware.ts
packages/middleware-jwt/src/jwt.middleware.ts
@@ -8,9 +8,10 @@ export type AuthorizeMiddlewareConfig = VerifyOptions;
const assignPayloadToRequest = (req: HttpRequest) => (payload: object) => req.user = payload;
-export const authorize$ =
- (config: AuthorizeMiddlewareConfig) =>
- (verifyPayload$: (payload: any) => Observable<object>): Middleware => req$ =>
+export const authorize$ = (
+ config: AuthorizeMiddlewareConfig,
+ verifyPayload$: (payload: any) => Observable<object>,
+): Middleware => req$ =>
req$.pipe(
flatMap(req => of(req).pipe(
map(parseAuthorizationHeader),

MODIFY
packages/middleware-jwt/src/spec/jwt.middleware.spec.ts
packages/middleware-jwt/src/spec/jwt.middleware.spec.ts
@@ -42,7 +42,7 @@ describe('JWT middleware', () => {
utilModule.parseAuthorizationHeader = jest.fn(() => mockedToken);
factoryModule.verifyToken$ = jest.fn(() => () => of(mockedTokenPayload));
- const middleware$ = authorize$({ secret: mockedSecret })(verifyPayload$)(req$, res, undefined);
+ const middleware$ = authorize$({ secret: mockedSecret }, verifyPayload$)(req$, res, undefined);
// then
middleware$.subscribe(
@@ -73,7 +73,7 @@ describe('JWT middleware', () => {
utilModule.parseAuthorizationHeader = jest.fn(() => mockedToken);
factoryModule.verifyToken$ = jest.fn(() => () => throwError(expectedError));
- const middleware$ = authorize$({ secret: mockedSecret })(verifyPayload$)(req$, res, undefined);
+ const middleware$ = authorize$({ secret: mockedSecret }, verifyPayload$)(req$, res, undefined);
// then
middleware$.subscribe(
@@ -105,7 +105,7 @@ describe('JWT middleware', () => {
utilModule.parseAuthorizationHeader = jest.fn(() => mockedToken);
factoryModule.verifyToken$ = jest.fn(() => () => of(mockedTokenPayload));
- const middleware$ = authorize$({ secret: mockedSecret })(verifyPayload$)(req$, res, undefined);
+ const middleware$ = authorize$({ secret: mockedSecret }, verifyPayload$)(req$, res, undefined);
// then
middleware$.subscribe(

MODIFY
packages/middleware-jwt/test/api.integration.ts
packages/middleware-jwt/test/api.integration.ts
@@ -9,7 +9,7 @@ type Payload = { id: string, email: string};
export const SECRET_KEY = 'SOME_SSH_KEY';
-const verifyPayload$ = (payload: { id: string, email: string}) =>
+const verifyPayload$ = (payload: Payload) =>
of(payload).pipe(
flatMap(payload => iif(
() => payload.id !== 'test_id' || payload.email !== 'admin@admin.com',
@@ -19,7 +19,7 @@ const verifyPayload$ = (payload: { id: string, email: string}) =>
);
const authOptions = { secret: SECRET_KEY };
-const authorize$ = authorizeMiddleware$(authOptions)(verifyPayload$);
+const authorize$ = authorizeMiddleware$(authOptions, verifyPayload$);
const generateFakeJWTPayload = ({ email }: LoginCredentials): Payload => ({ id: 'test_id', email });
const login$ = EffectFactory

refactor(middleware-jwt): verifyPayload$ as second argument