3.5.2 • Published 4 years ago

@marblejs/middleware-jwt v3.5.2

Weekly downloads
166
License
MIT
Repository
github
Last release
4 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

4 years ago

3.5.1

4 years ago

4.0.0-next.11

4 years ago

4.0.0-next.9

4 years ago

4.0.0-next.8

4 years ago

4.0.0-next.0

4 years ago

4.0.0-next.2

4 years ago

3.5.0

4 years ago

3.4.9

4 years ago

3.4.8

5 years ago

3.4.7

5 years ago

3.4.6

5 years ago

3.4.5

5 years ago

3.4.4

5 years ago

3.4.3

5 years ago

3.4.2

5 years ago

3.4.2-dev.5

5 years ago

3.4.2-dev.6

5 years ago

3.4.2-dev.3

5 years ago

3.4.1

5 years ago

3.4.0

5 years ago

3.4.0-dev.8

5 years ago

3.4.0-dev.6

5 years ago

3.4.0-dev.5

5 years ago

3.3.0

5 years ago

3.3.0-dev.26

5 years ago

3.3.0-dev.25

5 years ago

3.3.0-dev.24

5 years ago

3.3.0-dev.23

5 years ago

3.3.0-dev.18

5 years ago

3.3.0-dev.19

5 years ago

3.3.0-dev.17

5 years ago

3.3.0-dev.16

5 years ago

3.3.0-dev.14

5 years ago

3.3.0-dev.13

5 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

3.0.0-rc.5

5 years ago

3.0.0-rc.4

5 years ago

3.0.0-rc.3

5 years ago

3.0.0-rc.2

5 years ago

3.0.0-rc.1

5 years ago

3.0.0-rc.0

5 years ago

3.0.0-next.106

5 years ago

3.0.0-next.105

5 years ago

3.0.0-next.101

5 years ago

3.0.0-next.98

6 years ago

3.0.0-next.97

6 years ago

3.0.0-next.94

6 years ago

3.0.0-next.96

6 years ago

3.0.0-next.92

6 years ago

3.0.0-next.91

6 years ago

3.0.0-next.90

6 years ago

3.0.0-next.89

6 years ago

3.0.0-next.88

6 years ago

3.0.0-next.87

6 years ago

3.0.0-next.84

6 years ago

3.0.0-next.83

6 years ago

3.0.0-next.82

6 years ago

3.0.0-next.81

6 years ago

3.0.0-next.80

6 years ago

3.0.0-next.77

6 years ago

3.0.0-next.78

6 years ago

3.0.0-next.76

6 years ago

3.0.0-next.75

6 years ago

3.0.0-next.74

6 years ago

3.0.0-next.73

6 years ago

3.0.0-next.72

6 years ago

3.0.0-next.71

6 years ago

3.0.0-next.70

6 years ago

3.0.0-next.69

6 years ago

3.0.0-next.68

6 years ago

3.0.0-next.66

6 years ago

3.0.0-next.64

6 years ago

3.0.0-next.63

6 years ago

2.4.0-dev.51

6 years ago

2.4.0-dev.48

6 years ago

2.4.0-dev.45

6 years ago

2.4.0-dev.44

6 years ago

2.4.0-dev.42

6 years ago

2.4.0-dev.37

6 years ago

2.4.0-dev.36

6 years ago

2.4.0-dev.35

6 years ago

2.4.0-dev.34

6 years ago

2.3.0-dev.23

6 years ago

2.3.0-dev.22

6 years ago

2.3.0-dev.21

6 years ago

2.3.1

6 years ago

2.3.0

6 years ago

2.2.3

6 years ago

2.3.0-dev.11

6 years ago

2.3.0-dev.10

6 years ago

2.3.0-dev.9

6 years ago

2.3.0-dev.7

6 years ago

2.2.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.1

6 years ago

2.1.0-dev.8

6 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

2.0.0-rc.3

6 years ago

2.0.0-rc.2

6 years ago

2.0.0-next.2

6 years ago

2.0.0-rc.1

6 years ago

2.0.0-rc.0

6 years ago

2.0.0-next.26

6 years ago

2.0.0-next.24

6 years ago

2.0.0-next.23

6 years ago

1.3.0-dev.22

6 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.1.0-dev.10

7 years ago

1.1.0-dev.8

7 years ago