@falconeta/capacitor-aws-amplify 0.0.8 → 0.0.9

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
@@ -83,10 +83,10 @@ fetchAuthSession() => Promise<CognitoAuthSession>
83
83
  ### signOut()
84
84
 
85
85
  ```typescript
86
- signOut() => Promise<any>
86
+ signOut() => Promise<{ status: AwsAmplifyPluginResponseStatus; }>
87
87
  ```
88
88
 
89
- **Returns:** <code>Promise&lt;any&gt;</code>
89
+ **Returns:** <code>Promise&lt;{ status: <a href="#awsamplifypluginresponsestatus">AwsAmplifyPluginResponseStatus</a>; }&gt;</code>
90
90
 
91
91
  --------------------
92
92
 
@@ -123,10 +123,12 @@ signOut() => Promise<any>
123
123
 
124
124
  #### AwsAmplifyPluginResponseStatus
125
125
 
126
- | Members | Value |
127
- | -------- | --------------- |
128
- | **`Ok`** | <code>0</code> |
129
- | **`Ko`** | <code>-1</code> |
126
+ | Members | Value |
127
+ | --------------- | --------------- |
128
+ | **`Ok`** | <code>0</code> |
129
+ | **`Ko`** | <code>-1</code> |
130
+ | **`Cancelled`** | <code>-2</code> |
131
+ | **`SignedOut`** | <code>-3</code> |
130
132
 
131
133
 
132
134
  #### CognitoHostedUIIdentityProvider
@@ -38,18 +38,18 @@ import java.util.function.Consumer;
38
38
 
39
39
  public class AwsAmplify {
40
40
 
41
- @RequiresApi(api = Build.VERSION_CODES.N)
42
- public void load(JSObject cognitoConfig, Context context, @NonNull Consumer onSuccess, @NonNull Consumer<Exception> onError) {
41
+ @RequiresApi(api = Build.VERSION_CODES.N)
42
+ public void load(JSObject cognitoConfig, Context context, @NonNull Consumer onSuccess, @NonNull Consumer<Exception> onError) {
43
43
 
44
- JSObject oauth = (JSObject) cognitoConfig.getJSObject("oauth");
44
+ JSObject oauth = (JSObject) cognitoConfig.getJSObject("oauth");
45
45
 
46
- try {
47
- JSONObject auth = new JSONObject();
48
- auth.put("plugins", new JSONObject().put(
46
+ try {
47
+ JSONObject auth = new JSONObject();
48
+ auth.put("plugins", new JSONObject().put(
49
49
  "awsCognitoAuthPlugin", new JSONObject().put(
50
50
  "IdentityManager", new JSONObject().put(
51
51
  "Default", new JSONObject())
52
- ).put(
52
+ ).put(
53
53
  "CredentialsProvider", new JSONObject().put(
54
54
  "CognitoIdentity", new JSONObject().put(
55
55
  "Default", new JSONObject().put(
@@ -88,97 +88,101 @@ public class AwsAmplify {
88
88
  )
89
89
  )
90
90
  )
91
- )
92
- );
93
-
94
- Amplify.addPlugin(new AWSCognitoAuthPlugin());
95
- AuthCategoryConfiguration authConfig = new AuthCategoryConfiguration();
96
- authConfig.populateFromJSON(auth);
97
- Map<String, CategoryConfiguration> config = new HashMap();
98
- config.put("auth", authConfig);
99
- AmplifyConfiguration configuration = new AmplifyConfiguration(config);
100
- Amplify.configure(configuration, context);
101
- onSuccess.accept(null);
102
- } catch (AmplifyException e) {
103
- onError.accept(e);
104
- } catch (JSONException e) {
105
- onError.accept(e);
106
- throw new RuntimeException(e);
107
- }
108
-
91
+ )
92
+ );
93
+
94
+ Amplify.addPlugin(new AWSCognitoAuthPlugin());
95
+ AuthCategoryConfiguration authConfig = new AuthCategoryConfiguration();
96
+ authConfig.populateFromJSON(auth);
97
+ Map<String, CategoryConfiguration> config = new HashMap();
98
+ config.put("auth", authConfig);
99
+ AmplifyConfiguration configuration = new AmplifyConfiguration(config);
100
+ Amplify.configure(configuration, context);
101
+ onSuccess.accept(null);
102
+ } catch (AmplifyException e) {
103
+ onError.accept(e);
104
+ } catch (JSONException e) {
105
+ onError.accept(e);
106
+ throw new RuntimeException(e);
109
107
  }
110
108
 
109
+ }
110
+
111
111
 
112
112
  @RequiresApi(api = Build.VERSION_CODES.N)
113
- public void federatedSignIn(String providerString, Activity activity, @NonNull Consumer<AuthSignInResult> onSuccess,
114
- @NonNull Consumer<AuthException> onError) {
115
- AuthProvider provider = null;
113
+ public void federatedSignIn(String providerString, Activity activity, @NonNull Consumer<JSObject> onSuccess,
114
+ @NonNull Consumer<Exception> onError) {
115
+ AuthProvider provider = AuthProvider.google();
116
116
 
117
- if (providerString != null) {
118
- if (providerString.equals("Google")) {
119
- provider = AuthProvider.google();
120
- }
117
+ if (providerString.equals("facebook")) {
118
+ provider = AuthProvider.facebook();
119
+ }
121
120
 
122
- if (providerString.equals("facebook")) {
123
- provider = AuthProvider.facebook();
124
- }
121
+ if (providerString.equals("SignInWithApple")) {
122
+ provider = AuthProvider.apple();
123
+ }
125
124
 
126
- if (providerString.equals("apple")) {
127
- provider = AuthProvider.apple();
128
- }
125
+ AuthProvider finalProvider = provider;
126
+ fetchAuthSession(response -> {
127
+ var status = -1;
129
128
 
129
+ try {
130
+ status = response.getInt("status");
131
+ } catch (JSONException e) {
132
+ onError.accept(e);
133
+ return;
134
+ }
130
135
 
131
- if (provider != null) {
136
+ if (status == 0) {
137
+ onSuccess.accept(response);
138
+ } else {
132
139
  Amplify.Auth.signInWithSocialWebUI(
133
- provider,
140
+ finalProvider,
134
141
  activity,
135
142
  result -> {
136
- onSuccess.accept(result);
137
-
138
- // mAwsService.fetchAuthSession(
139
- // call::resolve,
140
- // error -> {
141
- // Log.e(TAG, "session error: ", error);
142
- // call.reject(error.toString());
143
- // });
143
+ fetchAuthSession(
144
+ onSuccess,
145
+ onError);
144
146
  },
145
147
  error -> {
146
148
  onError.accept(error);
147
149
  });
148
150
  }
149
- }
151
+ }, error -> {
152
+ onError.accept(error);
153
+ });
154
+
155
+
150
156
  }
151
157
 
152
158
  @RequiresApi(api = Build.VERSION_CODES.N)
153
159
  public void fetchAuthSession(@Nullable Consumer<JSObject> onSuccess,
154
160
  @Nullable Consumer<Exception> onError) {
155
- // mFetching = true;
156
-
157
161
  fetchSessionInternal(
158
162
  authSession -> {
159
- // mFetching = false;
160
163
 
161
164
  if (authSession != null && onSuccess != null) {
162
- onSuccess.accept(authSession.toJson());
165
+ JSObject ret = new JSObject();
166
+ ret.put("status", 0);
167
+ ret.put("accessToken", authSession.getAccessToken());
168
+ ret.put("idToken", authSession.getIdToken());
169
+ ret.put("identityId", authSession.getIdentityId());
170
+ ret.put("refreshToken", authSession.getRefreshToken());
171
+ ret.put("deviceKey", authSession.getDeviceKey());
172
+ onSuccess.accept(ret);
163
173
  }
164
174
  },
165
175
  error -> {
166
- // mFetching = false;
167
-
168
176
  if (onError != null) {
169
177
  String message = error.getMessage();
170
178
  String suggestion = error.getRecoverySuggestion();
171
179
  Throwable cause = error.getCause();
172
-
173
- // AwsAuthException authException;
174
- //
175
- // if (message != null && cause != null) {
176
- // authException = new AwsAuthException(message, cause, suggestion);
177
- // } else
178
- // authException = new AwsAuthException(
179
- // Objects.requireNonNullElse(message, "Aws Auth Error"), "Generic");
180
-
181
- onError.accept(error);
180
+ JSObject ret = new JSObject();
181
+ ret.put("status", -1);
182
+ if (AuthException.SignedOutException.class.isInstance(error)) {
183
+ ret.put("status", -3);
184
+ }
185
+ onSuccess.accept(ret);
182
186
  }
183
187
  });
184
188
  }
@@ -242,15 +246,15 @@ public class AwsAmplify {
242
246
  String idToken = tokens.getIdToken().getTokenString();
243
247
  String refreshToken = tokens.getRefreshToken().getTokenString();
244
248
 
245
- DeviceOperations deviceOperations = mClient.getDeviceOperations();
246
- ListDevicesResult devicesList = deviceOperations.list();
247
- List<Device> devices = devicesList.getDevices();
249
+ // DeviceOperations deviceOperations = mClient.getDeviceOperations();
250
+ // ListDevicesResult devicesList = deviceOperations.list();
251
+ // List<Device> devices = devicesList.getDevices();
248
252
 
249
253
  String deviceKey = null;
250
254
 
251
- if (!devices.isEmpty()) {
252
- deviceKey = deviceOperations.get().getDeviceKey();
253
- }
255
+ // if (!devices.isEmpty()) {
256
+ // deviceKey = deviceOperations.get().getDeviceKey();
257
+ // }
254
258
 
255
259
  return AwsAuthSession.builder(mClient.getIdentityId())
256
260
  .setAccessToken(accessToken)
@@ -270,12 +274,18 @@ public class AwsAmplify {
270
274
  * @param onError error callback.
271
275
  */
272
276
  @RequiresApi(api = Build.VERSION_CODES.N)
273
- public void signOut(@NonNull Consumer<Boolean> onSuccess,
277
+ public void signOut(@NonNull Consumer<JSObject> onSuccess,
274
278
  @NonNull Consumer<AuthException> onError) {
279
+ JSObject ret = new JSObject();
280
+
275
281
  Amplify.Auth.signOut(
276
- () -> onSuccess.accept(true),
282
+ () -> {
283
+ ret.put("status", 0);
284
+ onSuccess.accept(ret);
285
+ },
277
286
  error -> {
278
- onError.accept(error);
287
+ ret.put("status", -1);
288
+ onSuccess.accept(ret);
279
289
  }
280
290
  );
281
291
  }
@@ -34,7 +34,7 @@ public class AwsAmplifyPlugin extends Plugin {
34
34
  public void signOut(PluginCall call) {
35
35
 
36
36
  implementation.signOut(
37
- result -> call.resolve(),
37
+ result -> call.resolve(result),
38
38
  error -> {
39
39
  call.reject(error.toString());
40
40
  });
@@ -48,22 +48,20 @@ public class AwsAmplifyPlugin extends Plugin {
48
48
  implementation.federatedSignIn(
49
49
  provider,
50
50
  this.getActivity(),
51
- result -> call.resolve(),
51
+ result -> call.resolve(result),
52
52
  error -> {
53
53
  call.reject(error.toString());
54
54
  });
55
- // onSuccess: { data in
56
- // self.implementation.fetchAuthSession(
57
- // onSuccess: {session in
58
- // call.resolve(session)
59
- // },
60
- // onError: {error in
61
- // call.reject(error.localizedDescription)
62
- // })
55
+ }
56
+
57
+ @RequiresApi(api = Build.VERSION_CODES.N)
58
+ @PluginMethod
59
+ public void fetchAuthSession(PluginCall call) {
63
60
 
64
- // onError: { error in
65
- // print(error)
66
- // call.reject(error.localizedDescription)
67
- // })
61
+ implementation.fetchAuthSession(
62
+ result -> call.resolve(result),
63
+ error -> {
64
+ call.reject(error.toString());
65
+ });
68
66
  }
69
67
  }
package/dist/docs.json CHANGED
@@ -74,12 +74,14 @@
74
74
  },
75
75
  {
76
76
  "name": "signOut",
77
- "signature": "() => Promise<any>",
77
+ "signature": "() => Promise<{ status: AwsAmplifyPluginResponseStatus; }>",
78
78
  "parameters": [],
79
- "returns": "Promise<any>",
79
+ "returns": "Promise<{ status: AwsAmplifyPluginResponseStatus; }>",
80
80
  "tags": [],
81
81
  "docs": "",
82
- "complexTypes": [],
82
+ "complexTypes": [
83
+ "AwsAmplifyPluginResponseStatus"
84
+ ],
83
85
  "slug": "signout"
84
86
  }
85
87
  ],
@@ -163,7 +165,7 @@
163
165
  "tags": [],
164
166
  "docs": "",
165
167
  "complexTypes": [],
166
- "type": "string"
168
+ "type": "string | undefined"
167
169
  },
168
170
  {
169
171
  "name": "refreshToken",
@@ -177,7 +179,7 @@
177
179
  "tags": [],
178
180
  "docs": "",
179
181
  "complexTypes": [],
180
- "type": "string | null"
182
+ "type": "string | null | undefined"
181
183
  },
182
184
  {
183
185
  "name": "status",
@@ -207,6 +209,18 @@
207
209
  "value": "-1",
208
210
  "tags": [],
209
211
  "docs": ""
212
+ },
213
+ {
214
+ "name": "Cancelled",
215
+ "value": "-2",
216
+ "tags": [],
217
+ "docs": ""
218
+ },
219
+ {
220
+ "name": "SignedOut",
221
+ "value": "-3",
222
+ "tags": [],
223
+ "docs": ""
210
224
  }
211
225
  ]
212
226
  },
@@ -10,14 +10,16 @@ export interface AwsAmplifyPlugin {
10
10
  provider: CognitoHostedUIIdentityProvider;
11
11
  }): Promise<CognitoAuthSession>;
12
12
  fetchAuthSession(): Promise<CognitoAuthSession>;
13
- signOut(): Promise<any>;
13
+ signOut(): Promise<{
14
+ status: AwsAmplifyPluginResponseStatus;
15
+ }>;
14
16
  }
15
17
  export interface CognitoAuthSession {
16
18
  accessToken?: string;
17
19
  idToken?: string;
18
- identityId: string;
20
+ identityId?: string;
19
21
  refreshToken?: string;
20
- deviceKey: string | null;
22
+ deviceKey?: string | null;
21
23
  status: AwsAmplifyPluginResponseStatus;
22
24
  }
23
25
  export interface AWSCognitoConfig {
@@ -36,7 +38,9 @@ export interface AWSCognitoConfig {
36
38
  }
37
39
  export declare enum AwsAmplifyPluginResponseStatus {
38
40
  Ok = 0,
39
- Ko = -1
41
+ Ko = -1,
42
+ Cancelled = -2,
43
+ SignedOut = -3
40
44
  }
41
45
  export declare enum CognitoHostedUIIdentityProvider {
42
46
  Cognito = "COGNITO",
@@ -2,6 +2,8 @@ export var AwsAmplifyPluginResponseStatus;
2
2
  (function (AwsAmplifyPluginResponseStatus) {
3
3
  AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["Ok"] = 0] = "Ok";
4
4
  AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["Ko"] = -1] = "Ko";
5
+ AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["Cancelled"] = -2] = "Cancelled";
6
+ AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["SignedOut"] = -3] = "SignedOut";
5
7
  })(AwsAmplifyPluginResponseStatus || (AwsAmplifyPluginResponseStatus = {}));
6
8
  export var CognitoHostedUIIdentityProvider;
7
9
  (function (CognitoHostedUIIdentityProvider) {
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAqCA,MAAM,CAAN,IAAY,8BAGX;AAHD,WAAY,8BAA8B;IACxC,+EAAM,CAAA;IACN,gFAAO,CAAA;AACT,CAAC,EAHW,8BAA8B,KAA9B,8BAA8B,QAGzC;AAED,MAAM,CAAN,IAAY,+BAMX;AAND,WAAY,+BAA+B;IACzC,sDAAmB,CAAA;IACnB,oDAAiB,CAAA;IACjB,wDAAqB,CAAA;IACrB,6DAA0B,CAAA;IAC1B,4DAAyB,CAAA;AAC3B,CAAC,EANW,+BAA+B,KAA/B,+BAA+B,QAM1C","sourcesContent":["export interface AwsAmplifyPlugin {\n load(options: { cognitoConfig: AWSCognitoConfig }): Promise<void>;\n signIn(options: {\n email: string;\n password: string;\n }): Promise<CognitoAuthSession>;\n federatedSignIn(options: {\n provider: CognitoHostedUIIdentityProvider;\n }): Promise<CognitoAuthSession>;\n fetchAuthSession(): Promise<CognitoAuthSession>;\n signOut(): Promise<any>;\n}\n\nexport interface CognitoAuthSession {\n accessToken?: string;\n idToken?: string;\n identityId: string;\n refreshToken?: string;\n deviceKey: string | null;\n status: AwsAmplifyPluginResponseStatus\n}\n\nexport interface AWSCognitoConfig {\n aws_cognito_region: string;\n aws_user_pools_id: string;\n aws_user_pools_web_client_id: string;\n aws_cognito_identity_pool_id: string;\n aws_mandatory_sign_in: string;\n oauth: {\n domain: string;\n scope: string[];\n redirectSignIn: string;\n redirectSignOut: string;\n responseType: 'code';\n };\n}\n\nexport enum AwsAmplifyPluginResponseStatus {\n Ok = 0,\n Ko = -1\n}\n\nexport enum CognitoHostedUIIdentityProvider {\n Cognito = \"COGNITO\",\n Google = \"Google\",\n Facebook = \"Facebook\",\n Amazon = \"LoginWithAmazon\",\n Apple = \"SignInWithApple\"\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAqCA,MAAM,CAAN,IAAY,8BAKX;AALD,WAAY,8BAA8B;IACxC,+EAAM,CAAA;IACN,gFAAO,CAAA;IACP,8FAAc,CAAA;IACd,8FAAc,CAAA;AAChB,CAAC,EALW,8BAA8B,KAA9B,8BAA8B,QAKzC;AAED,MAAM,CAAN,IAAY,+BAMX;AAND,WAAY,+BAA+B;IACzC,sDAAmB,CAAA;IACnB,oDAAiB,CAAA;IACjB,wDAAqB,CAAA;IACrB,6DAA0B,CAAA;IAC1B,4DAAyB,CAAA;AAC3B,CAAC,EANW,+BAA+B,KAA/B,+BAA+B,QAM1C","sourcesContent":["export interface AwsAmplifyPlugin {\n load(options: { cognitoConfig: AWSCognitoConfig }): Promise<void>;\n signIn(options: {\n email: string;\n password: string;\n }): Promise<CognitoAuthSession>;\n federatedSignIn(options: {\n provider: CognitoHostedUIIdentityProvider;\n }): Promise<CognitoAuthSession>;\n fetchAuthSession(): Promise<CognitoAuthSession>;\n signOut(): Promise<{status: AwsAmplifyPluginResponseStatus}>;\n}\n\nexport interface CognitoAuthSession {\n accessToken?: string;\n idToken?: string;\n identityId?: string;\n refreshToken?: string;\n deviceKey?: string | null;\n status: AwsAmplifyPluginResponseStatus\n}\n\nexport interface AWSCognitoConfig {\n aws_cognito_region: string;\n aws_user_pools_id: string;\n aws_user_pools_web_client_id: string;\n aws_cognito_identity_pool_id: string;\n aws_mandatory_sign_in: string;\n oauth: {\n domain: string;\n scope: string[];\n redirectSignIn: string;\n redirectSignOut: string;\n responseType: 'code';\n };\n}\n\nexport enum AwsAmplifyPluginResponseStatus {\n Ok = 0,\n Ko = -1,\n Cancelled = -2,\n SignedOut = -3\n}\n\nexport enum CognitoHostedUIIdentityProvider {\n Cognito = \"COGNITO\",\n Google = \"Google\",\n Facebook = \"Facebook\",\n Amazon = \"LoginWithAmazon\",\n Apple = \"SignInWithApple\"\n}\n"]}
package/dist/esm/web.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
2
  import type { AwsAmplifyPlugin, AWSCognitoConfig, CognitoAuthSession } from './definitions';
3
+ import { AwsAmplifyPluginResponseStatus } from './definitions';
3
4
  export declare class AwsAmplifyWeb extends WebPlugin implements AwsAmplifyPlugin {
4
5
  private cognitoConfig?;
5
6
  load(options: {
@@ -13,6 +14,8 @@ export declare class AwsAmplifyWeb extends WebPlugin implements AwsAmplifyPlugin
13
14
  provider: string;
14
15
  }): Promise<CognitoAuthSession>;
15
16
  fetchAuthSession(): Promise<CognitoAuthSession>;
16
- signOut(): Promise<any>;
17
+ signOut(): Promise<{
18
+ status: AwsAmplifyPluginResponseStatus;
19
+ }>;
17
20
  private getCognitoAuthSession;
18
21
  }
package/dist/esm/web.js CHANGED
@@ -10,8 +10,16 @@ export class AwsAmplifyWeb extends WebPlugin {
10
10
  if (!this.cognitoConfig) {
11
11
  throw new Error('call load first');
12
12
  }
13
- const user = (await Auth.signIn(options.email, options.password));
14
- return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
13
+ try {
14
+ const user = (await Auth.signIn(options.email, options.password));
15
+ return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
16
+ }
17
+ catch (error) {
18
+ const res = {
19
+ status: AwsAmplifyPluginResponseStatus.Ko,
20
+ };
21
+ return res;
22
+ }
15
23
  }
16
24
  async federatedSignIn(options) {
17
25
  // console.log(LOG_PREFIX, options);
@@ -25,16 +33,28 @@ export class AwsAmplifyWeb extends WebPlugin {
25
33
  if (!this.cognitoConfig) {
26
34
  throw new Error('call load first');
27
35
  }
28
- const user = await Auth.currentAuthenticatedUser();
29
- // console.log(LOG_PREFIX + " user", user);
30
- const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
31
- return cognitoAuthSession;
36
+ try {
37
+ const user = await Auth.currentAuthenticatedUser();
38
+ const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
39
+ return cognitoAuthSession;
40
+ }
41
+ catch (error) {
42
+ console.log(error);
43
+ const res = {
44
+ status: AwsAmplifyPluginResponseStatus.Ko,
45
+ };
46
+ return res;
47
+ }
32
48
  }
33
49
  async signOut() {
34
50
  if (!this.cognitoConfig) {
35
51
  throw new Error('call load first');
36
52
  }
37
- return Auth.signOut();
53
+ return Auth.signOut()
54
+ .then(() => ({
55
+ status: AwsAmplifyPluginResponseStatus.Ok,
56
+ }))
57
+ .catch(() => ({ status: AwsAmplifyPluginResponseStatus.Ko }));
38
58
  }
39
59
  getCognitoAuthSession(user, identityId) {
40
60
  const userSession = user.getSignInUserSession();
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAO5C,OAAO,EAAE,8BAA8B,EAAE,MAAM,eAAe,CAAC;AAE/D,MAAM,OAAO,aAAc,SAAQ,SAAS;IAG1C,KAAK,CA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,CAAC;SACpC;QACD,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAEO,qBAAqB,CAAC,IAAiB,EAAE,UAAkB;QACjE,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAEhD,MAAM,GAAG,GAAuB;YAC9B,WAAW,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,cAAc,GAAG,WAAW,EAAE;YACxD,OAAO,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,UAAU,GAAG,WAAW,EAAE;YAChD,UAAU,EAAE,UAAU;YACtB,YAAY,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,eAAe,GAAG,QAAQ,EAAE;YACvD,SAAS,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,cAAc,GAAG,aAAa,GAAG,UAAU;YACnE,MAAM,EAAE,WAAW;gBACjB,CAAC,CAAC,8BAA8B,CAAC,EAAE;gBACnC,CAAC,CAAC,8BAA8B,CAAC,EAAE;SACtC,CAAC;QACF,OAAO,GAAG,CAAC;IACb,CAAC;CACF","sourcesContent":["import type { FederatedSignInOptions } from '@aws-amplify/auth/lib/types';\nimport { WebPlugin } from '@capacitor/core';\nimport type { CognitoUser } from 'amazon-cognito-identity-js';\nimport { Amplify, Auth } from 'aws-amplify';\n\nimport type {\n AwsAmplifyPlugin,\n AWSCognitoConfig,\n CognitoAuthSession,\n} from './definitions';\nimport { AwsAmplifyPluginResponseStatus } from './definitions';\n\nexport class AwsAmplifyWeb extends WebPlugin implements AwsAmplifyPlugin {\n private cognitoConfig?: AWSCognitoConfig;\n\n async load(options: { cognitoConfig: AWSCognitoConfig }): Promise<void> {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure({ ...options.cognitoConfig });\n }\n async signIn(options: {\n email: string;\n password: string;\n }): Promise<CognitoAuthSession> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n\n const user = (await Auth.signIn(\n options.email,\n options.password,\n )) as CognitoUser;\n\n return this.getCognitoAuthSession(\n user,\n this.cognitoConfig.aws_cognito_identity_pool_id,\n );\n }\n\n async federatedSignIn(options: {\n provider: string;\n }): Promise<CognitoAuthSession> {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n await Auth.federatedSignIn(options as FederatedSignInOptions);\n return this.fetchAuthSession();\n }\n\n async fetchAuthSession(): Promise<CognitoAuthSession> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n const user = await Auth.currentAuthenticatedUser();\n // console.log(LOG_PREFIX + \" user\", user);\n const cognitoAuthSession: CognitoAuthSession = this.getCognitoAuthSession(\n user,\n this.cognitoConfig.aws_cognito_identity_pool_id,\n );\n\n return cognitoAuthSession;\n }\n\n async signOut(): Promise<any> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return Auth.signOut();\n }\n\n private getCognitoAuthSession(user: CognitoUser, identityId: string) {\n const userSession = user.getSignInUserSession();\n\n const res: CognitoAuthSession = {\n accessToken: userSession?.getAccessToken().getJwtToken(),\n idToken: userSession?.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession?.getRefreshToken().getToken(),\n deviceKey: userSession?.getAccessToken().decodePayload().device_key,\n status: userSession\n ? AwsAmplifyPluginResponseStatus.Ok\n : AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n}\n"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAO5C,OAAO,EAAE,8BAA8B,EAAE,MAAM,eAAe,CAAC;AAE/D,MAAM,OAAO,aAAc,SAAQ,SAAS;IAG1C,KAAK,CAAC,IAAI,CAAC,OAA4C;QACrD,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;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AC,KAAK,CAAC,CAAC;YACnB,MAAM,GAAG,GAAuB;gBAC9B,MAAM,EAAE,8BAA8B,CAAC,EAAE;aAC1C,CAAC;YACF,OAAO,GAAG,CAAC;SACZ;IACH,CAAC;IAED,KAAK,CAAC,OAAO;QACX,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;SACpC;QACD,OAAO,IAAI,CAAC,OAAO,EAAE;aAClB,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;YACX,MAAM,EAAE,8BAA8B,CAAC,EAAE;SAC1C,CAAC,CAAC;aACF,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,8BAA8B,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAClE,CAAC;IAEO,qBAAqB,CAAC,IAAiB,EAAE,UAAkB;QACjE,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAEhD,MAAM,GAAG,GAAuB;YAC9B,WAAW,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,cAAc,GAAG,WAAW,EAAE;YACxD,OAAO,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,UAAU,GAAG,WAAW,EAAE;YAChD,UAAU,EAAE,UAAU;YACtB,YAAY,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,eAAe,GAAG,QAAQ,EAAE;YACvD,SAAS,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,cAAc,GAAG,aAAa,GAAG,UAAU;YACnE,MAAM,EAAE,WAAW;gBACjB,CAAC,CAAC,8BAA8B,CAAC,EAAE;gBACnC,CAAC,CAAC,8BAA8B,CAAC,EAAE;SACtC,CAAC;QACF,OAAO,GAAG,CAAC;IACb,CAAC;CACF","sourcesContent":["import type { FederatedSignInOptions } from '@aws-amplify/auth/lib/types';\nimport { WebPlugin } from '@capacitor/core';\nimport type { CognitoUser } from 'amazon-cognito-identity-js';\nimport { Amplify, Auth } from 'aws-amplify';\n\nimport type {\n AwsAmplifyPlugin,\n AWSCognitoConfig,\n CognitoAuthSession,\n} from './definitions';\nimport { AwsAmplifyPluginResponseStatus } from './definitions';\n\nexport class AwsAmplifyWeb extends WebPlugin implements AwsAmplifyPlugin {\n private cognitoConfig?: AWSCognitoConfig;\n\n async load(options: { cognitoConfig: AWSCognitoConfig }): Promise<void> {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure({ ...options.cognitoConfig });\n }\n async signIn(options: {\n email: string;\n password: string;\n }): Promise<CognitoAuthSession> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = (await Auth.signIn(\n options.email,\n options.password,\n )) as CognitoUser;\n\n return this.getCognitoAuthSession(\n user,\n this.cognitoConfig.aws_cognito_identity_pool_id,\n );\n } catch (error) {\n const res: CognitoAuthSession = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n }\n\n async federatedSignIn(options: {\n provider: string;\n }): Promise<CognitoAuthSession> {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n await Auth.federatedSignIn(options as FederatedSignInOptions);\n return this.fetchAuthSession();\n }\n\n async fetchAuthSession(): Promise<CognitoAuthSession> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n const cognitoAuthSession: CognitoAuthSession = this.getCognitoAuthSession(\n user,\n this.cognitoConfig.aws_cognito_identity_pool_id,\n );\n\n return cognitoAuthSession;\n } catch (error) {\n console.log(error);\n const res: CognitoAuthSession = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n }\n\n async signOut(): Promise<{ status: AwsAmplifyPluginResponseStatus }> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return Auth.signOut()\n .then(() => ({\n status: AwsAmplifyPluginResponseStatus.Ok,\n }))\n .catch(() => ({ status: AwsAmplifyPluginResponseStatus.Ko }));\n }\n\n private getCognitoAuthSession(user: CognitoUser, identityId: string) {\n const userSession = user.getSignInUserSession();\n\n const res: CognitoAuthSession = {\n accessToken: userSession?.getAccessToken().getJwtToken(),\n idToken: userSession?.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession?.getRefreshToken().getToken(),\n deviceKey: userSession?.getAccessToken().decodePayload().device_key,\n status: userSession\n ? AwsAmplifyPluginResponseStatus.Ok\n : AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n}\n"]}
@@ -9,6 +9,8 @@ exports.AwsAmplifyPluginResponseStatus = void 0;
9
9
  (function (AwsAmplifyPluginResponseStatus) {
10
10
  AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["Ok"] = 0] = "Ok";
11
11
  AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["Ko"] = -1] = "Ko";
12
+ AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["Cancelled"] = -2] = "Cancelled";
13
+ AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["SignedOut"] = -3] = "SignedOut";
12
14
  })(exports.AwsAmplifyPluginResponseStatus || (exports.AwsAmplifyPluginResponseStatus = {}));
13
15
  exports.CognitoHostedUIIdentityProvider = void 0;
14
16
  (function (CognitoHostedUIIdentityProvider) {
@@ -32,8 +34,16 @@ class AwsAmplifyWeb extends core.WebPlugin {
32
34
  if (!this.cognitoConfig) {
33
35
  throw new Error('call load first');
34
36
  }
35
- const user = (await awsAmplify.Auth.signIn(options.email, options.password));
36
- return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
37
+ try {
38
+ const user = (await awsAmplify.Auth.signIn(options.email, options.password));
39
+ return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
40
+ }
41
+ catch (error) {
42
+ const res = {
43
+ status: exports.AwsAmplifyPluginResponseStatus.Ko,
44
+ };
45
+ return res;
46
+ }
37
47
  }
38
48
  async federatedSignIn(options) {
39
49
  // console.log(LOG_PREFIX, options);
@@ -47,16 +57,28 @@ class AwsAmplifyWeb extends core.WebPlugin {
47
57
  if (!this.cognitoConfig) {
48
58
  throw new Error('call load first');
49
59
  }
50
- const user = await awsAmplify.Auth.currentAuthenticatedUser();
51
- // console.log(LOG_PREFIX + " user", user);
52
- const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
53
- return cognitoAuthSession;
60
+ try {
61
+ const user = await awsAmplify.Auth.currentAuthenticatedUser();
62
+ const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
63
+ return cognitoAuthSession;
64
+ }
65
+ catch (error) {
66
+ console.log(error);
67
+ const res = {
68
+ status: exports.AwsAmplifyPluginResponseStatus.Ko,
69
+ };
70
+ return res;
71
+ }
54
72
  }
55
73
  async signOut() {
56
74
  if (!this.cognitoConfig) {
57
75
  throw new Error('call load first');
58
76
  }
59
- return awsAmplify.Auth.signOut();
77
+ return awsAmplify.Auth.signOut()
78
+ .then(() => ({
79
+ status: exports.AwsAmplifyPluginResponseStatus.Ok,
80
+ }))
81
+ .catch(() => ({ status: exports.AwsAmplifyPluginResponseStatus.Ko }));
60
82
  }
61
83
  getCognitoAuthSession(user, identityId) {
62
84
  const userSession = user.getSignInUserSession();
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export var AwsAmplifyPluginResponseStatus;\n(function (AwsAmplifyPluginResponseStatus) {\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Ok\"] = 0] = \"Ok\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Ko\"] = -1] = \"Ko\";\n})(AwsAmplifyPluginResponseStatus || (AwsAmplifyPluginResponseStatus = {}));\nexport var CognitoHostedUIIdentityProvider;\n(function (CognitoHostedUIIdentityProvider) {\n CognitoHostedUIIdentityProvider[\"Cognito\"] = \"COGNITO\";\n CognitoHostedUIIdentityProvider[\"Google\"] = \"Google\";\n CognitoHostedUIIdentityProvider[\"Facebook\"] = \"Facebook\";\n CognitoHostedUIIdentityProvider[\"Amazon\"] = \"LoginWithAmazon\";\n CognitoHostedUIIdentityProvider[\"Apple\"] = \"SignInWithApple\";\n})(CognitoHostedUIIdentityProvider || (CognitoHostedUIIdentityProvider = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Amplify, Auth } from 'aws-amplify';\nimport { AwsAmplifyPluginResponseStatus } from './definitions';\nexport class AwsAmplifyWeb extends WebPlugin {\n async load(options) {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure(Object.assign({}, options.cognitoConfig));\n }\n async signIn(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n const user = (await Auth.signIn(options.email, options.password));\n return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n }\n async federatedSignIn(options) {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n await Auth.federatedSignIn(options);\n return this.fetchAuthSession();\n }\n async fetchAuthSession() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n const user = await Auth.currentAuthenticatedUser();\n // console.log(LOG_PREFIX + \" user\", user);\n const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n return cognitoAuthSession;\n }\n async signOut() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return Auth.signOut();\n }\n getCognitoAuthSession(user, identityId) {\n const userSession = user.getSignInUserSession();\n const res = {\n accessToken: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().getJwtToken(),\n idToken: userSession === null || userSession === void 0 ? void 0 : userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession === null || userSession === void 0 ? void 0 : userSession.getRefreshToken().getToken(),\n deviceKey: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().decodePayload().device_key,\n status: userSession\n ? AwsAmplifyPluginResponseStatus.Ok\n : AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["AwsAmplifyPluginResponseStatus","CognitoHostedUIIdentityProvider","registerPlugin","WebPlugin","Amplify","Auth"],"mappings":";;;;;;;AAAWA,gDAA+B;AAC1C,CAAC,UAAU,8BAA8B,EAAE;AAC3C,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;AACpF,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;AACrF,CAAC,EAAEA,sCAA8B,KAAKA,sCAA8B,GAAG,EAAE,CAAC,CAAC,CAAC;AACjEC,iDAAgC;AAC3C,CAAC,UAAU,+BAA+B,EAAE;AAC5C,IAAI,+BAA+B,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;AAC3D,IAAI,+BAA+B,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;AACzD,IAAI,+BAA+B,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;AAC7D,IAAI,+BAA+B,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CAAC;AAClE,IAAI,+BAA+B,CAAC,OAAO,CAAC,GAAG,iBAAiB,CAAC;AACjE,CAAC,EAAEA,uCAA+B,KAAKA,uCAA+B,GAAG,EAAE,CAAC,CAAC;;ACXxE,MAAC,UAAU,GAAGC,mBAAc,CAAC,YAAY,EAAE;AAChD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAA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AE;AACnD,SAAS,CAAC;AACV,QAAQ,OAAO,GAAG,CAAC;AACnB,KAAK;AACL;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export var AwsAmplifyPluginResponseStatus;\n(function (AwsAmplifyPluginResponseStatus) {\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Ok\"] = 0] = \"Ok\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Ko\"] = -1] = \"Ko\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Cancelled\"] = -2] = \"Cancelled\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"SignedOut\"] = -3] = \"SignedOut\";\n})(AwsAmplifyPluginResponseStatus || (AwsAmplifyPluginResponseStatus = {}));\nexport var CognitoHostedUIIdentityProvider;\n(function (CognitoHostedUIIdentityProvider) {\n CognitoHostedUIIdentityProvider[\"Cognito\"] = \"COGNITO\";\n CognitoHostedUIIdentityProvider[\"Google\"] = \"Google\";\n CognitoHostedUIIdentityProvider[\"Facebook\"] = \"Facebook\";\n CognitoHostedUIIdentityProvider[\"Amazon\"] = \"LoginWithAmazon\";\n CognitoHostedUIIdentityProvider[\"Apple\"] = \"SignInWithApple\";\n})(CognitoHostedUIIdentityProvider || (CognitoHostedUIIdentityProvider = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Amplify, Auth } from 'aws-amplify';\nimport { AwsAmplifyPluginResponseStatus } from './definitions';\nexport class AwsAmplifyWeb extends WebPlugin {\n async load(options) {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure(Object.assign({}, options.cognitoConfig));\n }\n async signIn(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = (await Auth.signIn(options.email, options.password));\n return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n }\n catch (error) {\n const res = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n }\n async federatedSignIn(options) {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n await Auth.federatedSignIn(options);\n return this.fetchAuthSession();\n }\n async fetchAuthSession() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n return cognitoAuthSession;\n }\n catch (error) {\n console.log(error);\n const res = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n }\n async signOut() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return Auth.signOut()\n .then(() => ({\n status: AwsAmplifyPluginResponseStatus.Ok,\n }))\n .catch(() => ({ status: AwsAmplifyPluginResponseStatus.Ko }));\n }\n getCognitoAuthSession(user, identityId) {\n const userSession = user.getSignInUserSession();\n const res = {\n accessToken: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().getJwtToken(),\n idToken: userSession === null || userSession === void 0 ? void 0 : userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession === null || userSession === void 0 ? void 0 : userSession.getRefreshToken().getToken(),\n deviceKey: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().decodePayload().device_key,\n status: userSession\n ? AwsAmplifyPluginResponseStatus.Ok\n : AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["AwsAmplifyPluginResponseStatus","CognitoHostedUIIdentityProvider","registerPlugin","WebPlugin","Amplify","Auth"],"mappings":";;;;;;;AAAWA,gDA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E,UAAU;AAClC,YAAY,YAAY,EAAE,WAAW,KAAK,IAAI,IAAI,WAAW,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,WAAW,CAAC,eAAe,EAAE,CAAC,QAAQ,EAAE;AAC5H,YAAY,SAAS,EAAE,WAAW,KAAK,IAAI,IAAI,WAAW,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,WAAW,CAAC,cAAc,EAAE,CAAC,aAAa,EAAE,CAAC,UAAU;AACxI,YAAY,MAAM,EAAE,WAAW;AAC/B,kBAAkBA,sCAA8B,CAAC,EAAE;AACnD,kBAAkBA,sCAA8B,CAAC,EAAE;AACnD,SAAS,CAAC;AACV,QAAQ,OAAO,GAAG,CAAC;AACnB,KAAK;AACL;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -5,6 +5,8 @@ var capacitorAwsAmplify = (function (exports, core, awsAmplify) {
5
5
  (function (AwsAmplifyPluginResponseStatus) {
6
6
  AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["Ok"] = 0] = "Ok";
7
7
  AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["Ko"] = -1] = "Ko";
8
+ AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["Cancelled"] = -2] = "Cancelled";
9
+ AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["SignedOut"] = -3] = "SignedOut";
8
10
  })(exports.AwsAmplifyPluginResponseStatus || (exports.AwsAmplifyPluginResponseStatus = {}));
9
11
  exports.CognitoHostedUIIdentityProvider = void 0;
10
12
  (function (CognitoHostedUIIdentityProvider) {
@@ -28,8 +30,16 @@ var capacitorAwsAmplify = (function (exports, core, awsAmplify) {
28
30
  if (!this.cognitoConfig) {
29
31
  throw new Error('call load first');
30
32
  }
31
- const user = (await awsAmplify.Auth.signIn(options.email, options.password));
32
- return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
33
+ try {
34
+ const user = (await awsAmplify.Auth.signIn(options.email, options.password));
35
+ return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
36
+ }
37
+ catch (error) {
38
+ const res = {
39
+ status: exports.AwsAmplifyPluginResponseStatus.Ko,
40
+ };
41
+ return res;
42
+ }
33
43
  }
34
44
  async federatedSignIn(options) {
35
45
  // console.log(LOG_PREFIX, options);
@@ -43,16 +53,28 @@ var capacitorAwsAmplify = (function (exports, core, awsAmplify) {
43
53
  if (!this.cognitoConfig) {
44
54
  throw new Error('call load first');
45
55
  }
46
- const user = await awsAmplify.Auth.currentAuthenticatedUser();
47
- // console.log(LOG_PREFIX + " user", user);
48
- const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
49
- return cognitoAuthSession;
56
+ try {
57
+ const user = await awsAmplify.Auth.currentAuthenticatedUser();
58
+ const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
59
+ return cognitoAuthSession;
60
+ }
61
+ catch (error) {
62
+ console.log(error);
63
+ const res = {
64
+ status: exports.AwsAmplifyPluginResponseStatus.Ko,
65
+ };
66
+ return res;
67
+ }
50
68
  }
51
69
  async signOut() {
52
70
  if (!this.cognitoConfig) {
53
71
  throw new Error('call load first');
54
72
  }
55
- return awsAmplify.Auth.signOut();
73
+ return awsAmplify.Auth.signOut()
74
+ .then(() => ({
75
+ status: exports.AwsAmplifyPluginResponseStatus.Ok,
76
+ }))
77
+ .catch(() => ({ status: exports.AwsAmplifyPluginResponseStatus.Ko }));
56
78
  }
57
79
  getCognitoAuthSession(user, identityId) {
58
80
  const userSession = user.getSignInUserSession();
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export var AwsAmplifyPluginResponseStatus;\n(function (AwsAmplifyPluginResponseStatus) {\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Ok\"] = 0] = \"Ok\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Ko\"] = -1] = \"Ko\";\n})(AwsAmplifyPluginResponseStatus || (AwsAmplifyPluginResponseStatus = {}));\nexport var CognitoHostedUIIdentityProvider;\n(function (CognitoHostedUIIdentityProvider) {\n CognitoHostedUIIdentityProvider[\"Cognito\"] = \"COGNITO\";\n CognitoHostedUIIdentityProvider[\"Google\"] = \"Google\";\n CognitoHostedUIIdentityProvider[\"Facebook\"] = \"Facebook\";\n CognitoHostedUIIdentityProvider[\"Amazon\"] = \"LoginWithAmazon\";\n CognitoHostedUIIdentityProvider[\"Apple\"] = \"SignInWithApple\";\n})(CognitoHostedUIIdentityProvider || (CognitoHostedUIIdentityProvider = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Amplify, Auth } from 'aws-amplify';\nimport { AwsAmplifyPluginResponseStatus } from './definitions';\nexport class AwsAmplifyWeb extends WebPlugin {\n async load(options) {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure(Object.assign({}, options.cognitoConfig));\n }\n async signIn(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n const user = (await Auth.signIn(options.email, options.password));\n return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n }\n async federatedSignIn(options) {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n await Auth.federatedSignIn(options);\n return this.fetchAuthSession();\n }\n async fetchAuthSession() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n const user = await Auth.currentAuthenticatedUser();\n // console.log(LOG_PREFIX + \" user\", user);\n const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n return cognitoAuthSession;\n }\n async signOut() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return Auth.signOut();\n }\n getCognitoAuthSession(user, identityId) {\n const userSession = user.getSignInUserSession();\n const res = {\n accessToken: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().getJwtToken(),\n idToken: userSession === null || userSession === void 0 ? void 0 : userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession === null || userSession === void 0 ? void 0 : userSession.getRefreshToken().getToken(),\n deviceKey: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().decodePayload().device_key,\n status: userSession\n ? AwsAmplifyPluginResponseStatus.Ok\n : AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["AwsAmplifyPluginResponseStatus","CognitoHostedUIIdentityProvider","registerPlugin","WebPlugin","Amplify","Auth"],"mappings":";;;AAAWA,oDAA+B;IAC1C,CAAC,UAAU,8BAA8B,EAAE;IAC3C,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;IACpF,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACrF,CAAC,EAAEA,sCAA8B,KAAKA,sCAA8B,GAAG,EAAE,CAAC,CAAC,CAAC;AACjEC,qDAAgC;IAC3C,CAAC,UAAU,+BAA+B,EAAE;IAC5C,IAAI,+BAA+B,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;IAC3D,IAAI,+BAA+B,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;IACzD,IAAI,+BAA+B,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;IAC7D,IAAI,+BAA+B,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CAAC;IAClE,IAAI,+BAA+B,CAAC,OAAO,CAAC,GAAG,iBAAiB,CAAC;IACj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AK,CAAC,GAAG,WAAW,CAAC,cAAc,EAAE,CAAC,aAAa,EAAE,CAAC,UAAU;IACxI,YAAY,MAAM,EAAE,WAAW;IAC/B,kBAAkBL,sCAA8B,CAAC,EAAE;IACnD,kBAAkBA,sCAA8B,CAAC,EAAE;IACnD,SAAS,CAAC;IACV,QAAQ,OAAO,GAAG,CAAC;IACnB,KAAK;IACL;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export var AwsAmplifyPluginResponseStatus;\n(function (AwsAmplifyPluginResponseStatus) {\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Ok\"] = 0] = \"Ok\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Ko\"] = -1] = \"Ko\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Cancelled\"] = -2] = \"Cancelled\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"SignedOut\"] = -3] = \"SignedOut\";\n})(AwsAmplifyPluginResponseStatus || (AwsAmplifyPluginResponseStatus = {}));\nexport var CognitoHostedUIIdentityProvider;\n(function (CognitoHostedUIIdentityProvider) {\n CognitoHostedUIIdentityProvider[\"Cognito\"] = \"COGNITO\";\n CognitoHostedUIIdentityProvider[\"Google\"] = \"Google\";\n CognitoHostedUIIdentityProvider[\"Facebook\"] = \"Facebook\";\n CognitoHostedUIIdentityProvider[\"Amazon\"] = \"LoginWithAmazon\";\n CognitoHostedUIIdentityProvider[\"Apple\"] = \"SignInWithApple\";\n})(CognitoHostedUIIdentityProvider || (CognitoHostedUIIdentityProvider = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Amplify, Auth } from 'aws-amplify';\nimport { AwsAmplifyPluginResponseStatus } from './definitions';\nexport class AwsAmplifyWeb extends WebPlugin {\n async load(options) {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure(Object.assign({}, options.cognitoConfig));\n }\n async signIn(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = (await Auth.signIn(options.email, options.password));\n return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n }\n catch (error) {\n const res = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n }\n async federatedSignIn(options) {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n await Auth.federatedSignIn(options);\n return this.fetchAuthSession();\n }\n async fetchAuthSession() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n return cognitoAuthSession;\n }\n catch (error) {\n console.log(error);\n const res = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n }\n async signOut() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return Auth.signOut()\n .then(() => ({\n status: AwsAmplifyPluginResponseStatus.Ok,\n }))\n .catch(() => ({ status: AwsAmplifyPluginResponseStatus.Ko }));\n }\n getCognitoAuthSession(user, identityId) {\n const userSession = user.getSignInUserSession();\n const res = {\n accessToken: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().getJwtToken(),\n idToken: userSession === null || userSession === void 0 ? void 0 : userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession === null || userSession === void 0 ? void 0 : userSession.getRefreshToken().getToken(),\n deviceKey: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().decodePayload().device_key,\n status: userSession\n ? AwsAmplifyPluginResponseStatus.Ok\n : AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["AwsAmplifyPluginResponseStatus","CognitoHostedUIIdentityProvider","registerPlugin","WebPlugin","Amplify","Auth"],"mappings":";;;AAAWA,oDAA+B;IAC1C,CAAC,UAAU,8BAA8B,EAAE;IAC3C,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;IACpF,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACrF,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;IACnG,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;IACnG,CAAC,EAAEA,sCAA8B,KAAKA,sCAA8B,GAAG,EAAE,CAAC,CAAC,CAAC;AACjEC,qDAAgC;IAC3C,CAAC,UAAU,+BAA+B,EAAE;IAC5C,IAAI,+BAA+B,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;IAC3D,IAAI,+BAA+B,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;IACzD,IAAI,+BAA+B,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;IAC7D,IAAI,+BAA+B,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CAAC;IAClE,IAAI,+BAA+B,CAAC,OAAO,CAAC,GAAG,iBAAiB,CAAC;IACjE,CAAC,EAAEA,uCAA+B,KAAKA,uCAA+B,GAAG,EAAE,CAAC,CAAC;;ACbxE,UAAC,UAAU,GAAGC,mBAAc,CAAC,YAAY,EAAE;IAChD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;IAC/D,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W,EAAE;IAC7H,YAAY,OAAO,EAAE,WAAW,KAAK,IAAI,IAAI,WAAW,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,WAAW,CAAC,UAAU,EAAE,CAAC,WAAW,EAAE;IACrH,YAAY,UAAU,EAAE,UAAU;IAClC,YAAY,YAAY,EAAE,WAAW,KAAK,IAAI,IAAI,WAAW,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,WAAW,CAAC,eAAe,EAAE,CAAC,QAAQ,EAAE;IAC5H,YAAY,SAAS,EAAE,WAAW,KAAK,IAAI,IAAI,WAAW,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,WAAW,CAAC,cAAc,EAAE,CAAC,aAAa,EAAE,CAAC,UAAU;IACxI,YAAY,MAAM,EAAE,WAAW;IAC/B,kBAAkBA,sCAA8B,CAAC,EAAE;IACnD,kBAAkBA,sCAA8B,CAAC,EAAE;IACnD,SAAS,CAAC;IACV,QAAQ,OAAO,GAAG,CAAC;IACnB,KAAK;IACL;;;;;;;;;;;;;;;;;"}
@@ -48,7 +48,7 @@ import AWSMobileClient
48
48
 
49
49
  public func federatedSignIn(
50
50
  provider: String,
51
- onSuccess: @escaping (AuthSignInResult) -> (),
51
+ onSuccess: @escaping (JSObject) -> (),
52
52
  onError: @escaping (any Error) -> ()
53
53
  ) {
54
54
  var authProvider: AuthProvider
@@ -72,13 +72,20 @@ import AWSMobileClient
72
72
  DispatchQueue.main.async {
73
73
  Amplify.Auth.signInWithWebUI(for: authProvider,
74
74
  presentationAnchor: UIApplication.shared.windows.first!, options: .preferPrivateSession()) { result in
75
+ var ret: JSObject = [:]
75
76
  switch result {
76
- case .success(let result):
77
- print("\(self.TAG) federatedSignIn effettuato con successo: \(result)")
78
- onSuccess(result)
77
+ case .success(_):
78
+ ret["status"] = 0
79
+ onSuccess(ret)
79
80
  case .failure(let error):
80
- print("\(self.TAG) Impossibile effettuare il federatedSignIn: \(error)")
81
- onError(error)
81
+ let cognitoAuthError = error.underlyingError as? AWSCognitoAuthError
82
+ switch cognitoAuthError {
83
+ case .userCancelled:
84
+ ret["status"] = -2
85
+ default:
86
+ ret["status"] = -1
87
+ }
88
+ onSuccess(ret)
82
89
  }
83
90
  }
84
91
  }
@@ -86,16 +93,20 @@ import AWSMobileClient
86
93
  }
87
94
 
88
95
  public func signOut(
89
- onSuccess: @escaping (Bool) -> (),
96
+ onSuccess: @escaping (JSObject) -> (),
90
97
  onError: @escaping (any Error) -> ()
91
98
  ) {
92
99
  Amplify.Auth.signOut() { result in
100
+ var ret: JSObject = [:]
101
+
93
102
  switch result {
94
103
  case .success:
95
- onSuccess(true)
104
+ ret["status"] = 0
105
+ onSuccess(ret)
96
106
  case .failure(let authError):
97
107
  print("\(self.TAG) Sign out failed with error \(authError)")
98
- onError(authError)
108
+ ret["status"] = -1
109
+ onSuccess(ret)
99
110
  }
100
111
  }
101
112
  }
@@ -133,16 +144,6 @@ import AWSMobileClient
133
144
  ret["idToken"] = tokens.idToken
134
145
  ret["refreshToken"] = tokens.refreshToken
135
146
 
136
- // Amplify.Auth.fetchDevices { result in
137
- // switch result {
138
- // case .success(let devices):
139
- // print("\(self.TAG) devices", devices)
140
- // print("\(self.TAG) device IDs", devices.map(\.id))
141
- // case .failure(let error):
142
- // print("\(self.TAG) error", error)
143
- // }
144
- // }
145
-
146
147
  // Retrieve the device key from the payload of access token
147
148
  let accessToken = tokens.accessToken as NSString
148
149
  // print("\(self.TAG) accessToken - \(tokens.idToken) ")
@@ -162,8 +163,21 @@ import AWSMobileClient
162
163
  // print("\(self.TAG) - \(ret)")
163
164
  onSuccess(ret)
164
165
  } catch {
166
+ var ret: JSObject = [:]
167
+ ret["status"] = -1
168
+ if let authError = error as? AuthError
169
+ {
170
+ let cognitoAuthError = authError
171
+ switch cognitoAuthError {
172
+ case .signedOut:
173
+ ret["status"] = -3
174
+ default:
175
+ ret["status"] = -1
176
+ }
177
+ }
178
+
179
+ onSuccess(ret)
165
180
  print("\(self.TAG) Fetch auth session failed with error - \(error)")
166
- onError(error)
167
181
  }
168
182
  }
169
183
  }
@@ -47,10 +47,8 @@ public class AwsAmplifyPlugin: CAPPlugin {
47
47
 
48
48
  @objc func signOut(_ call: CAPPluginCall) {
49
49
  self.implementation.signOut(
50
- onSuccess: { success in
51
- call.resolve([
52
- "logout": success
53
- ])
50
+ onSuccess: { response in
51
+ call.resolve(response)
54
52
  }, onError: { error in
55
53
  call.reject(error.localizedDescription)
56
54
  })
@@ -59,22 +57,32 @@ public class AwsAmplifyPlugin: CAPPlugin {
59
57
  @objc func federatedSignIn(_ call: CAPPluginCall) {
60
58
  let provider = call.getString("provider") ?? ""
61
59
 
62
- self.implementation.federatedSignIn(
63
- provider: provider,
64
- onSuccess: { data in
65
- print("federatedSignIn onSuccess \(data)")
66
- self.implementation.fetchAuthSession(
67
- onSuccess: {session in
68
- call.resolve(session)
69
- },
70
- onError: {error in
71
- call.reject(error.localizedDescription)
72
- })
60
+ self.implementation.fetchAuthSession(
61
+ onSuccess: {session in
62
+ if(session["status"] as! Int == 0) {
63
+ call.resolve(session)
64
+ } else {
65
+ self.implementation.federatedSignIn(
66
+ provider: provider,
67
+ onSuccess: { result in
68
+ if(result["status"] as! Int == 0) {
69
+ self.fetchAuthSession(call)
70
+ } else {
71
+ call.resolve(result)
72
+ }
73
+ },
74
+ onError: { error in
75
+ print(error)
76
+ call.reject(error.localizedDescription)
77
+ })
78
+ }
79
+
73
80
  },
74
- onError: { error in
75
- print(error)
81
+ onError: {error in
76
82
  call.reject(error.localizedDescription)
77
83
  })
84
+
85
+
78
86
  }
79
87
  @objc func fetchAuthSession(_ call: CAPPluginCall) {
80
88
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@falconeta/capacitor-aws-amplify",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "plugin that handle amplify features",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",