3.5.2 • Published 3 years ago

@marblejs/middleware-jwt v3.5.2

Weekly downloads
166
License
MIT
Repository
github
Last release
3 years ago

@marblejs/middleware-jwt

A JWT middleware for Marble.js.

Installation

$ npm i @marblejs/middleware-jwt

Requires @marblejs/core to be installed.

Usage

Generate token:

import { EffectFactory } from '@marblejs/core';
import { generateToken } from '@marblejs/middleware-jwt';
import { SECRET_KEY } from './config';

const login$ = EffectFactory
  .matchPath('/login')
  .matchType('POST')
  .use(req$ => req$.pipe(
    //
    map(payload => generateToken({ secret: SECRET_KEY })(payload)), 👈
    // ...
  ));

Validate payload:

const verifyPayload$ = (payload: { id: string }) =>
  of(payload).pipe(
    map(payload => payload.id),
    flatMap(UserRepository.findById),  // the repository can throw an error if not found or...
    catchError(/* ... */)              // the `verifyPayload$` can throw it explicitly
  );

Validate routes:

import { r } from '@marblejs/core';
import { authorize$ } from '@marblejs/middleware-jwt';
import { SECRET_KEY } from './config';

const getUsers$ = r.pipe(
  r.matchPath('/'),
  r.matchType('GET'),
  r.useEffect(req$ => req$.pipe(
    // ...
  )));

const user$ = combineRoutes('/user', {
  effects: [
    getUsers$
  ],
  middlewares: [
    authorize$({ secret: SECRET_KEY }, validatePayload$) 👈
  ],
});

License: MIT

3.5.2

3 years ago

3.5.1

3 years ago

4.0.0-next.11

3 years ago

4.0.0-next.9

3 years ago

4.0.0-next.8

3 years ago

4.0.0-next.0

3 years ago

4.0.0-next.2

3 years ago

3.5.0

3 years ago

3.4.9

3 years ago

3.4.8

3 years ago

3.4.7

3 years ago

3.4.6

3 years ago

3.4.5

3 years ago

3.4.4

3 years ago

3.4.3

4 years ago

3.4.2

4 years ago

3.4.2-dev.5

4 years ago

3.4.2-dev.6

4 years ago

3.4.2-dev.3

4 years ago

3.4.1

4 years ago

3.4.0

4 years ago

3.4.0-dev.8

4 years ago

3.4.0-dev.6

4 years ago

3.4.0-dev.5

4 years ago

3.3.0

4 years ago

3.3.0-dev.26

4 years ago

3.3.0-dev.25

4 years ago

3.3.0-dev.24

4 years ago

3.3.0-dev.23

4 years ago

3.3.0-dev.18

4 years ago

3.3.0-dev.19

4 years ago

3.3.0-dev.17

4 years ago

3.3.0-dev.16

4 years ago

3.3.0-dev.14

4 years ago

3.3.0-dev.13

4 years ago

3.2.1

4 years ago

3.2.0

4 years ago

3.1.2

4 years ago

3.1.1

4 years ago

3.1.0

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

3.0.0-rc.5

4 years ago

3.0.0-rc.4

4 years ago

3.0.0-rc.3

4 years ago

3.0.0-rc.2

4 years ago

3.0.0-rc.1

4 years ago

3.0.0-rc.0

4 years ago

3.0.0-next.106

4 years ago

3.0.0-next.105

4 years ago

3.0.0-next.101

4 years ago

3.0.0-next.98

4 years ago

3.0.0-next.97

4 years ago

3.0.0-next.94

4 years ago

3.0.0-next.96

4 years ago

3.0.0-next.92

4 years ago

3.0.0-next.91

4 years ago

3.0.0-next.90

4 years ago

3.0.0-next.89

4 years ago

3.0.0-next.88

4 years ago

3.0.0-next.87

4 years ago

3.0.0-next.84

4 years ago

3.0.0-next.83

4 years ago

3.0.0-next.82

4 years ago

3.0.0-next.81

4 years ago

3.0.0-next.80

4 years ago

3.0.0-next.77

4 years ago

3.0.0-next.78

4 years ago

3.0.0-next.76

4 years ago

3.0.0-next.75

5 years ago

3.0.0-next.74

5 years ago

3.0.0-next.73

5 years ago

3.0.0-next.72

5 years ago

3.0.0-next.71

5 years ago

3.0.0-next.70

5 years ago

3.0.0-next.69

5 years ago

3.0.0-next.68

5 years ago

3.0.0-next.66

5 years ago

3.0.0-next.64

5 years ago

3.0.0-next.63

5 years ago

2.4.0-dev.51

5 years ago

2.4.0-dev.48

5 years ago

2.4.0-dev.45

5 years ago

2.4.0-dev.44

5 years ago

2.4.0-dev.42

5 years ago

2.4.0-dev.37

5 years ago

2.4.0-dev.36

5 years ago

2.4.0-dev.35

5 years ago

2.4.0-dev.34

5 years ago

2.3.0-dev.23

5 years ago

2.3.0-dev.22

5 years ago

2.3.0-dev.21

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.3

5 years ago

2.3.0-dev.11

5 years ago

2.3.0-dev.10

5 years ago

2.3.0-dev.9

5 years ago

2.3.0-dev.7

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.1

5 years ago

2.1.0-dev.8

5 years ago

2.1.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

2.0.0-rc.3

5 years ago

2.0.0-rc.2

5 years ago

2.0.0-next.2

5 years ago

2.0.0-rc.1

5 years ago

2.0.0-rc.0

5 years ago

2.0.0-next.26

5 years ago

2.0.0-next.24

5 years ago

2.0.0-next.23

5 years ago

1.3.0-dev.22

5 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.1.0-dev.10

6 years ago

1.1.0-dev.8

6 years ago