@unsource/ui 2.8.18 → 2.8.19

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "unsource-ui",
3
3
  "configKey": "unsourceUi",
4
- "version": "2.8.18",
4
+ "version": "2.8.19",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -8,6 +8,7 @@ declare global {
8
8
  urlPrefix?: string;
9
9
  }
10
10
  }
11
+ export declare const forceLogOut: () => Promise<void>;
11
12
  type Config = NitroFetchOptions<NitroFetchRequest, 'get' | 'post' | 'put' | 'delete'> & {
12
13
  headers?: Record<string, unknown>;
13
14
  };
@@ -18,11 +19,9 @@ export declare const fetch: <T>({ body, config, controller, URL, method, }: {
18
19
  URL?: string;
19
20
  method?: "GET" | "POST" | "PUT" | "DELETE";
20
21
  }) => Promise<{
21
- result: undefined;
22
- error: Record<string, Record<string, unknown>>;
22
+ error: any;
23
23
  } | {
24
24
  result: T;
25
- error: undefined;
26
25
  }>;
27
26
  export declare const useGet: <T>(URL: string, config?: NitroFetchOptions<NitroFetchRequest, "get"> & {
28
27
  headers?: Record<string, unknown>;
@@ -1,12 +1,25 @@
1
1
  import { useModuleConfig, useToken } from "./reuseable.js";
2
- import { _get, _set, useNuxtApp, isArray, isPlainObject } from "#imports";
2
+ import { _get, _set, useNuxtApp, isArray, isPlainObject, useUserId, useUser, navigateTo } from "#imports";
3
+ export const forceLogOut = async () => {
4
+ const userId = useUserId();
5
+ const user = useUser();
6
+ const tokenId = useToken();
7
+ userId.value = null;
8
+ user.value = {};
9
+ tokenId.value = null;
10
+ await navigateTo("/profile");
11
+ };
3
12
  const setHeaders = (config) => {
4
13
  const token = useToken();
5
14
  _set(config, ["headers", "Authorization"], _get(config, ["headers", "Authorization"], token.value || ""));
6
15
  _set(config, ["headers", "qt"], _get(config, ["headers", "qt"], "v2"));
7
16
  return config;
8
17
  };
9
- const errorHandler = (error, config) => {
18
+ const errorHandler = async (error, config) => {
19
+ if (error.status === 401) {
20
+ await forceLogOut();
21
+ return { error };
22
+ }
10
23
  if ("data" in error) {
11
24
  if (!config?.headers?.["no-error"]) {
12
25
  let msg = "";
@@ -17,7 +30,7 @@ const errorHandler = (error, config) => {
17
30
  $toast?.error(msg || JSON.stringify(error?.data));
18
31
  }
19
32
  }
20
- return { result: void 0, error };
33
+ return { error };
21
34
  };
22
35
  export const fetch = async ({
23
36
  body = void 0,
@@ -38,7 +51,7 @@ export const fetch = async ({
38
51
  body,
39
52
  ...config
40
53
  });
41
- return { result, error: void 0 };
54
+ return { result };
42
55
  } catch (error) {
43
56
  return errorHandler(error, config);
44
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unsource/ui",
3
- "version": "2.8.18",
3
+ "version": "2.8.19",
4
4
  "private": false,
5
5
  "description": "nuxt ui kit for unsource env",
6
6
  "repository": "https://github.com/alisa2142/unsource-ui",