FoalTS / foal

Full-featured Node.js framework 🚀
https://foalts.org/
MIT License
1.9k stars 142 forks source link

Add `userIdType` option to `@JWT` and `@UseSessions` and remove `fetchUser` interface and functions #1119

Closed LoicPoullain closed 2 years ago

LoicPoullain commented 2 years ago

Issue

See #1120

Solution and steps

Breaking changes and new features

// TODO: do the same with user with permissions.


Note on the use of MongoDB with TypeORM v0.3:
```typescript
 import { ObjectId } from 'mongodb';

  @JWTRequired({
    userIdType: 'string',
    user: (id: string) => User.findOneBy({ _id: new ObjectId(id) }),
  })

    @ObjectIdColumn()
    // Do not use
    id: ObjectID;
    // Use
    _id: ObjectID;

Checklist

codecov-commenter commented 2 years ago

Codecov Report

Merging #1119 (f912ba5) into v3-0-0 (a16759e) will increase coverage by 0.00%. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           v3-0-0    #1119   +/-   ##
=======================================
  Coverage   98.82%   98.83%           
=======================================
  Files          85       86    +1     
  Lines        1705     1719   +14     
  Branches      408      413    +5     
=======================================
+ Hits         1685     1699   +14     
  Misses         20       20           
Impacted Files Coverage Δ
packages/core/src/index.ts 0.00% <ø> (ø)
...kages/core/src/sessions/http/check-user-id-type.ts 100.00% <100.00%> (ø)
...e/src/sessions/http/get-session-id-from-request.ts 100.00% <100.00%> (ø)
packages/core/src/sessions/use-sessions.hook.ts 98.82% <100.00%> (+0.02%) :arrow_up:
packages/core/src/core/config/config.ts 94.28% <0.00%> (+0.05%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update a16759e...f912ba5. Read the comment docs.