@medusajs/auth 0.0.3 → 0.0.4-next-20240430121402

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.
@@ -1,5 +1,5 @@
1
- import { AbstractAuthModuleProvider } from "@medusajs/utils";
2
1
  import { AuthenticationInput, AuthenticationResponse } from "@medusajs/types";
2
+ import { AbstractAuthModuleProvider } from "@medusajs/utils";
3
3
  import { AuthUserService } from "../services";
4
4
  declare class EmailPasswordProvider extends AbstractAuthModuleProvider {
5
5
  static PROVIDER: string;
@@ -1,16 +1,14 @@
1
- import { AuthenticationInput, AuthenticationResponse, ModulesSdkTypes } from "@medusajs/types";
1
+ import { AuthenticationInput, AuthenticationResponse } from "@medusajs/types";
2
2
  import { AbstractAuthModuleProvider } from "@medusajs/utils";
3
3
  import { AuthUserService } from "../services";
4
4
  type InjectedDependencies = {
5
5
  authUserService: AuthUserService;
6
- authProviderService: ModulesSdkTypes.InternalModuleService<any>;
7
6
  };
8
7
  declare class GoogleProvider extends AbstractAuthModuleProvider {
9
8
  static PROVIDER: string;
10
9
  static DISPLAY_NAME: string;
11
10
  protected readonly authUserService_: AuthUserService;
12
- protected readonly authProviderService_: ModulesSdkTypes.InternalModuleService<any>;
13
- constructor({ authUserService, authProviderService }: InjectedDependencies);
11
+ constructor({ authUserService }: InjectedDependencies);
14
12
  authenticate(req: AuthenticationInput): Promise<AuthenticationResponse>;
15
13
  validateCallback(req: AuthenticationInput): Promise<AuthenticationResponse>;
16
14
  verify_(refreshToken: string): Promise<{
@@ -8,13 +8,12 @@ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
8
8
  const simple_oauth2_1 = require("simple-oauth2");
9
9
  const url_1 = __importDefault(require("url"));
10
10
  class GoogleProvider extends utils_1.AbstractAuthModuleProvider {
11
- constructor({ authUserService, authProviderService }) {
11
+ constructor({ authUserService }) {
12
12
  super(arguments[0], {
13
13
  provider: GoogleProvider.PROVIDER,
14
14
  displayName: GoogleProvider.DISPLAY_NAME,
15
15
  });
16
16
  this.authUserService_ = authUserService;
17
- this.authProviderService_ = authProviderService;
18
17
  }
19
18
  async authenticate(req) {
20
19
  if (req.query?.error) {
@@ -75,7 +74,10 @@ class GoogleProvider extends utils_1.AbstractAuthModuleProvider {
75
74
  return { success: false, error: error.message };
76
75
  }
77
76
  }
78
- return { success: true, authUser };
77
+ return {
78
+ success: true,
79
+ authUser,
80
+ };
79
81
  }
80
82
  // abstractable
81
83
  async validateCallbackToken(code, { clientID, callbackURL, clientSecret }) {
@@ -86,7 +88,13 @@ class GoogleProvider extends utils_1.AbstractAuthModuleProvider {
86
88
  };
87
89
  try {
88
90
  const accessToken = await client.getToken(tokenParams);
89
- return await this.verify_(accessToken.token.id_token);
91
+ const { authUser, success } = await this.verify_(accessToken.token.id_token);
92
+ const { successRedirectUrl } = this.getConfigFromScope();
93
+ return {
94
+ success,
95
+ authUser,
96
+ successRedirectUrl,
97
+ };
90
98
  }
91
99
  catch (error) {
92
100
  return { success: false, error: error.message };
@@ -112,7 +120,6 @@ class GoogleProvider extends utils_1.AbstractAuthModuleProvider {
112
120
  return protocol + "://" + host + path;
113
121
  }
114
122
  async getProviderConfig(req) {
115
- await this.authProviderService_.retrieve(GoogleProvider.PROVIDER);
116
123
  const config = this.getConfigFromScope();
117
124
  const callbackURL = config.callbackURL;
118
125
  const parsedCallbackUrl = !url_1.default.parse(callbackURL).protocol
@@ -1,12 +1,14 @@
1
1
  import { AuthTypes, Context, DAL, FindConfig, RepositoryService } from "@medusajs/types";
2
2
  import { AuthUser } from "../models";
3
3
  type InjectedDependencies = {
4
+ baseRepository: DAL.RepositoryService;
4
5
  authUserRepository: DAL.RepositoryService;
5
6
  };
6
7
  declare const AuthUserService_base: new <TEntity_1 extends object = any>(container: InjectedDependencies) => import("@medusajs/types").InternalModuleService<TEntity_1, InjectedDependencies>;
7
8
  export default class AuthUserService<TEntity extends AuthUser = AuthUser> extends AuthUserService_base<TEntity> {
8
9
  protected readonly authUserRepository_: RepositoryService<TEntity>;
10
+ protected baseRepository_: DAL.RepositoryService;
9
11
  constructor(container: InjectedDependencies);
10
- retrieveByProviderAndEntityId<TEntityMethod = AuthTypes.AuthUserDTO>(entityId: string, provider: string, config?: FindConfig<TEntityMethod>, sharedContext?: Context): Promise<TEntity>;
12
+ retrieveByProviderAndEntityId<TEntityMethod = AuthTypes.AuthUserDTO>(entityId: string, provider: string, config?: FindConfig<TEntityMethod>, sharedContext?: Context): Promise<AuthTypes.AuthUserDTO>;
11
13
  }
12
14
  export {};
@@ -19,6 +19,7 @@ class AuthUserService extends utils_1.ModulesSdkUtils.internalModuleServiceFacto
19
19
  // @ts-ignore
20
20
  super(...arguments);
21
21
  this.authUserRepository_ = container.authUserRepository;
22
+ this.baseRepository_ = container.baseRepository;
22
23
  }
23
24
  async retrieveByProviderAndEntityId(entityId, provider, config = {}, sharedContext = {}) {
24
25
  const queryConfig = utils_1.ModulesSdkUtils.buildQuery({ entity_id: entityId, provider }, { ...config, take: 1 });
@@ -26,7 +27,7 @@ class AuthUserService extends utils_1.ModulesSdkUtils.internalModuleServiceFacto
26
27
  if (!result) {
27
28
  throw new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_FOUND, `AuthUser with entity_id: "${entityId}" and provider: "${provider}" not found`);
28
29
  }
29
- return result;
30
+ return await this.baseRepository_.serialize(result);
30
31
  }
31
32
  }
32
33
  exports.default = AuthUserService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medusajs/auth",
3
- "version": "0.0.3",
3
+ "version": "0.0.4-next-20240430121402",
4
4
  "description": "Medusa Auth module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  "watch:test": "tsc --build tsconfig.spec.json --watch",
29
29
  "prepublishOnly": "cross-env NODE_ENV=production tsc --build && tsc-alias -p tsconfig.json",
30
30
  "build": "rimraf dist && tsc --build && tsc-alias -p tsconfig.json",
31
- "test": "jest --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts",
31
+ "test": "jest --runInBand --bail --passWithNoTests --forceExit -- src",
32
32
  "test:integration": "jest --forceExit -- integration-tests/**/__tests__/**/*.ts",
33
33
  "migration:generate": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:generate",
34
34
  "migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:create --initial",
@@ -40,7 +40,7 @@
40
40
  "@mikro-orm/cli": "5.9.7",
41
41
  "cross-env": "^5.2.1",
42
42
  "jest": "^29.6.3",
43
- "medusa-test-utils": "^1.1.42",
43
+ "medusa-test-utils": "1.1.44-next-20240430121402",
44
44
  "rimraf": "^3.0.2",
45
45
  "ts-jest": "^29.1.1",
46
46
  "ts-node": "^10.9.1",
@@ -48,9 +48,9 @@
48
48
  "typescript": "^5.1.6"
49
49
  },
50
50
  "dependencies": {
51
- "@medusajs/modules-sdk": "^1.12.9",
52
- "@medusajs/types": "^1.11.14",
53
- "@medusajs/utils": "^1.11.7",
51
+ "@medusajs/modules-sdk": "1.12.11-next-20240430121402",
52
+ "@medusajs/types": "1.11.16-next-20240430121402",
53
+ "@medusajs/utils": "1.11.9-next-20240430121402",
54
54
  "@mikro-orm/core": "5.9.7",
55
55
  "@mikro-orm/migrations": "5.9.7",
56
56
  "@mikro-orm/postgresql": "5.9.7",