@ave-id/embed 0.2.2 → 0.2.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.
Files changed (2) hide show
  1. package/dist/embed.js +29 -0
  2. package/package.json +4 -2
package/dist/embed.js CHANGED
@@ -85,6 +85,9 @@ export function openAveSheet({
85
85
  onError,
86
86
  onClose,
87
87
  }) {
88
+ let resolved = false;
89
+ let popup = null;
90
+
88
91
  // Create overlay backdrop
89
92
  const overlay = document.createElement("div");
90
93
  overlay.style.cssText = `
@@ -195,6 +198,9 @@ export function openAveSheet({
195
198
 
196
199
  // Close function
197
200
  const close = () => {
201
+ if (popup && !popup.closed) {
202
+ popup.close();
203
+ }
198
204
  sheet.style.animation = "aveSheetSlideDown 0.2s ease-in forwards";
199
205
  overlay.style.animation = "aveSheetFadeOut 0.2s ease-in forwards";
200
206
  setTimeout(() => {
@@ -215,17 +221,38 @@ export function openAveSheet({
215
221
  if (event.origin !== issuer) return;
216
222
  const data = event.data || {};
217
223
 
224
+ if (resolved) return;
225
+
226
+ if (data.type === "ave:auth_required") {
227
+ if (!popup || popup.closed) {
228
+ const width = 450;
229
+ const height = 650;
230
+ const left = (window.innerWidth - width) / 2 + window.screenX;
231
+ const top = (window.innerHeight - height) / 2 + window.screenY;
232
+ popup = window.open(
233
+ iframe.src,
234
+ "ave_auth",
235
+ `width=${width},height=${height},left=${left},top=${top},menubar=no,toolbar=no,location=no,status=no`
236
+ );
237
+ }
238
+ popup?.focus?.();
239
+ return;
240
+ }
241
+
218
242
  if (data.type === "ave:success") {
243
+ resolved = true;
219
244
  close();
220
245
  onSuccess?.(data.payload);
221
246
  }
222
247
 
223
248
  if (data.type === "ave:error") {
249
+ resolved = true;
224
250
  close();
225
251
  onError?.(data.payload);
226
252
  }
227
253
 
228
254
  if (data.type === "ave:close") {
255
+ resolved = true;
229
256
  close();
230
257
  }
231
258
  };
@@ -249,6 +276,7 @@ export function openAvePopup({
249
276
  redirectUri,
250
277
  scope = "openid profile email",
251
278
  issuer = "https://aveid.net",
279
+ theme = DEFAULT_THEME,
252
280
  codeChallenge,
253
281
  codeChallengeMethod,
254
282
  width = 450,
@@ -262,6 +290,7 @@ export function openAvePopup({
262
290
  redirect_uri: redirectUri,
263
291
  scope,
264
292
  embed: "1",
293
+ theme,
265
294
  });
266
295
 
267
296
  if (codeChallenge) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ave-id/embed",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "main": "dist/embed.js",
6
6
  "module": "dist/embed.js",
@@ -10,7 +10,9 @@
10
10
  "default": "./dist/embed.js"
11
11
  }
12
12
  },
13
- "files": ["dist"],
13
+ "files": [
14
+ "dist"
15
+ ],
14
16
  "publishConfig": {
15
17
  "access": "public"
16
18
  },