@merkaly/nuxt 0.1.12 → 0.1.13

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/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "0.1.12",
7
+ "version": "0.1.13",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -3,7 +3,7 @@ import { defineNuxtPlugin, useRuntimeConfig } from "#imports";
3
3
  import { navigateTo } from "#app";
4
4
  import { defu } from "defu";
5
5
  import { useAuth } from "../composables/useAuth.js";
6
- export default defineNuxtPlugin(async () => {
6
+ export default defineNuxtPlugin(async (nuxtApp) => {
7
7
  const { public: $config } = useRuntimeConfig();
8
8
  const auth0 = await createAuth0Client({
9
9
  cacheLocation: "localstorage",
@@ -29,6 +29,14 @@ export default defineNuxtPlugin(async () => {
29
29
  returnTo: URL.canParse($config.merkaly.auth0.logoutUrl) ? $config.merkaly.auth0.logoutUrl : location.origin.concat($config.merkaly.auth0.logoutUrl)
30
30
  }
31
31
  });
32
- Promise.allSettled([auth0.getUser(), auth0.getTokenSilently()]).catch(() => void 0).finally(() => isLoading.value = false);
32
+ Promise.allSettled([auth0.getUser(), auth0.getTokenSilently()]).then((results) => {
33
+ const rejected = results.filter((r) => r.status === "rejected");
34
+ if (rejected.length > 0) {
35
+ return nuxtApp.callHook("merkaly:auth:error", { errors: rejected.map((r) => r.reason) });
36
+ }
37
+ if (user.value) {
38
+ return nuxtApp.callHook("merkaly:auth:success", { user: user.value, token: token.value });
39
+ }
40
+ }).finally(() => isLoading.value = false);
33
41
  return { provide: { auth0 } };
34
42
  });
@@ -1,4 +1,4 @@
1
- import type { Auth0Client } from '@auth0/auth0-spa-js';
1
+ import type { Auth0Client, User } from '@auth0/auth0-spa-js';
2
2
  import type { ApiOptions } from '../plugins/api.global';
3
3
 
4
4
  declare module '#app' {
@@ -6,6 +6,11 @@ declare module '#app' {
6
6
  $auth0: Auth0Client;
7
7
  $api: (url: string, options?: ApiOptions) => Promise<void>;
8
8
  }
9
+
10
+ interface RuntimeNuxtHooks {
11
+ 'merkaly:auth:success': (payload: { user: User; token: string }) => void | Promise<void>;
12
+ 'merkaly:auth:error': (payload: { errors: unknown[] }) => void | Promise<void>;
13
+ }
9
14
  }
10
15
 
11
16
  declare module 'vue' {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@merkaly/nuxt",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/merkaly-io/nuxt.git"