@occupop/lib-auth 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -31,9 +31,8 @@ JWT_SECRET=randomTokenProvidedByAuthService
31
31
 
32
32
  ```typescript
33
33
  import {
34
- makeGraphqlServer, graphqlMiddleware, graphqlStandalone
35
- } from '@occupop/lib-graphql'
36
- import { resolvers } from './app/resolvers'
34
+ makeAuthContextValueFunction, makeAuthContextMiddleware
35
+ } from '@occupop/lib-auth'
37
36
  //... all other imports omited...
38
37
 
39
38
  export const container = createTypedContainer({
package/dist/index.d.ts CHANGED
@@ -23,10 +23,10 @@ export declare function makeAuthContextValueFunction<IContainer extends AwilixCo
23
23
  container: IContainer;
24
24
  }): ({ req }: {
25
25
  req: Request;
26
- }) => {
26
+ }) => Promise<{
27
27
  container: AwilixContainer<any>;
28
- };
28
+ }>;
29
29
  export declare function makeAuthContextMiddleware<IContainer extends AwilixContainer>({ container, }: {
30
30
  container: IContainer;
31
- }): (req: Request) => void;
31
+ }): (req: Request) => Promise<void>;
32
32
  export {};
package/dist/index.js CHANGED
@@ -32,21 +32,21 @@ export function getScopedUser(req) {
32
32
  return null;
33
33
  }
34
34
  export function makeAuthContextValueFunction({ container }) {
35
- return ({ req }) => {
35
+ return async ({ req }) => {
36
36
  const authUser = getAuthUser(req);
37
37
  const scopedUser = getScopedUser(req);
38
38
  const scopedContainer = container.createScope();
39
39
  if (authUser)
40
- container.register('authUser', asValue(authUser));
40
+ scopedContainer.register('authUser', asValue(authUser));
41
41
  if (scopedUser)
42
- container.register('scopedUser', asValue(scopedUser));
42
+ scopedContainer.register('scopedUser', asValue(scopedUser));
43
43
  return { container: scopedContainer };
44
44
  };
45
45
  }
46
46
  export function makeAuthContextMiddleware({ container, }) {
47
- return (req) => {
47
+ return async (req) => {
48
48
  const authContextValueFunction = makeAuthContextValueFunction({ container });
49
- const contextValue = authContextValueFunction({ req });
49
+ const contextValue = await authContextValueFunction({ req });
50
50
  req.container = contextValue.container;
51
51
  };
52
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@occupop/lib-auth",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "main": "dist/index.js",
5
5
  "module": "index.ts",
6
6
  "description": "...",