@inzombieland/nuxt-common 1.16.2 → 1.16.4

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@inzombieland/nuxt-common",
3
- "version": "1.16.2",
3
+ "version": "1.16.4",
4
4
  "configKey": "nuxt-common",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.6.0",
package/dist/module.mjs CHANGED
@@ -2,7 +2,7 @@ import { fileURLToPath } from 'node:url';
2
2
  import { defineNuxtModule, createResolver, addServerHandler, addImportsDir, addPlugin, addComponent } from '@nuxt/kit';
3
3
 
4
4
  const name = "@inzombieland/nuxt-common";
5
- const version = "1.16.2";
5
+ const version = "1.16.4";
6
6
 
7
7
  const module = defineNuxtModule({
8
8
  meta: {
@@ -1,13 +1,12 @@
1
1
  import { defineEventHandler, getRequestHeader, parseCookies } from "h3";
2
+ import { useRuntimeConfig } from "#imports";
2
3
  export default defineEventHandler(async (event) => {
3
4
  const cookies = parseCookies(event);
4
5
  if (cookies.lin !== "yes") {
5
6
  return {};
6
7
  }
7
- const config = {
8
- apiBaseURL: String(import.meta.env.VITE_API_BASE_URL)
9
- };
10
- const request = String(config.apiBaseURL) + String(event.node.req.url);
8
+ const config = useRuntimeConfig();
9
+ const request = String(config.public.apiBaseURL) + String(event.node.req.url);
11
10
  const authorization = getRequestHeader(event, "authorization") ?? "";
12
11
  try {
13
12
  const response = await $fetch.raw(request, {
@@ -1,13 +1,12 @@
1
1
  import { defineEventHandler, parseCookies } from "h3";
2
+ import { useRuntimeConfig } from "#imports";
2
3
  export default defineEventHandler(async (event) => {
3
4
  const cookies = parseCookies(event);
4
5
  if (cookies.lin !== "yes") {
5
6
  return {};
6
7
  }
7
- const config = {
8
- apiBaseURL: String(import.meta.env.VITE_API_BASE_URL)
9
- };
10
- const request = String(config.apiBaseURL) + String(event.node.req.url);
8
+ const config = useRuntimeConfig();
9
+ const request = String(config.public.apiBaseURL) + String(event.node.req.url);
11
10
  try {
12
11
  const response = await $fetch(request, {
13
12
  headers: event.context.headers
@@ -16,7 +15,7 @@ export default defineEventHandler(async (event) => {
16
15
  if (!token) {
17
16
  return {};
18
17
  }
19
- const user = await $fetch(`${config.apiBaseURL}/account`, {
18
+ const user = await $fetch(`${config.public.apiBaseURL}/account`, {
20
19
  headers: { ...event.context.headers, authorization: `JWT ${token}` }
21
20
  });
22
21
  if (!user) {
@@ -1,10 +1,9 @@
1
1
  import { cookieHelper } from "@inzombieland/nuxt-common/helpers";
2
2
  import { appendHeader, defineEventHandler, readBody } from "h3";
3
+ import { useRuntimeConfig } from "#imports";
3
4
  export default defineEventHandler(async (event) => {
4
- const config = {
5
- apiBaseURL: String(import.meta.env.VITE_API_BASE_URL)
6
- };
7
- const request = String(config.apiBaseURL) + String(event.node.req.url);
5
+ const config = useRuntimeConfig();
6
+ const request = String(config.public.apiBaseURL) + String(event.node.req.url);
8
7
  try {
9
8
  const body = await readBody(event);
10
9
  const response = await $fetch.raw(request, {
@@ -1,9 +1,7 @@
1
1
  import { defineEventHandler, getRequestHeader } from "h3";
2
+ import { useRuntimeConfig } from "#imports";
2
3
  export default defineEventHandler((event) => {
3
- const config = {
4
- appClientID: String(import.meta.env.VITE_APP_CLIENT_ID),
5
- appClientSecret: String(import.meta.env.VITE_APP_CLIENT_SECRET)
6
- };
4
+ const config = useRuntimeConfig();
7
5
  let authorization = "";
8
6
  if (import.meta.server && String(config.appClientID) && String(config.appClientSecret)) {
9
7
  const credentials = btoa(`${config.appClientID}:${config.appClientSecret}`);
@@ -1,14 +1,13 @@
1
1
  import { cookieHelper } from "@inzombieland/nuxt-common/helpers";
2
2
  import { appendHeader, defineEventHandler, parseCookies } from "h3";
3
+ import { useRuntimeConfig } from "#imports";
3
4
  export default defineEventHandler(async (event) => {
4
5
  const cookies = parseCookies(event);
5
6
  if (cookies.lin !== "yes") {
6
7
  return {};
7
8
  }
8
- const config = {
9
- apiBaseURL: String(import.meta.env.VITE_API_BASE_URL)
10
- };
11
- const request = String(config.apiBaseURL) + String(event.node.req.url);
9
+ const config = useRuntimeConfig();
10
+ const request = String(config.public.apiBaseURL) + String(event.node.req.url);
12
11
  try {
13
12
  const response = await $fetch.raw(request, {
14
13
  headers: event.context.headers
@@ -1,11 +1,12 @@
1
1
  import { defineNuxtRouteMiddleware, navigateTo } from "#app";
2
2
  import { useLocalePath } from "#i18n";
3
+ import { useRuntimeConfig } from "#imports";
3
4
  import { useUser } from "../composables/use-user.mjs";
4
5
  export default defineNuxtRouteMiddleware(() => {
5
6
  const user = useUser();
6
7
  if (user.value) {
7
8
  const localePath = useLocalePath();
8
- const baseURL = String(import.meta.env.VITE_BASE_URL);
9
+ const baseURL = useRuntimeConfig().public.baseURL ?? "";
9
10
  return navigateTo(localePath(baseURL));
10
11
  }
11
12
  });
@@ -1,16 +1,12 @@
1
1
  import { defineNuxtRouteMiddleware, navigateTo } from "#app";
2
- import { useCookie } from "#imports";
2
+ import { useCookie, useRuntimeConfig } from "#imports";
3
3
  import { useUser } from "../composables/use-user.mjs";
4
4
  export default defineNuxtRouteMiddleware((to) => {
5
5
  if (import.meta.server) return;
6
6
  const user = useUser();
7
7
  const { value: localeCookie } = useCookie("locale");
8
8
  const locale = user.value?.locale ?? localeCookie ?? "en";
9
- const config = {
10
- routingStrategy: String(import.meta.env.VITE_ROUTING_STRATEGY),
11
- defaultLocale: String(import.meta.env.VITE_DEFAULT_LOCALE)
12
- };
13
- const { routingStrategy, defaultLocale } = config;
9
+ const { routingStrategy, defaultLocale } = useRuntimeConfig().public;
14
10
  if (routingStrategy === "prefix" && to.path === `/${defaultLocale}` && locale !== defaultLocale) {
15
11
  return navigateTo(`/${locale}`);
16
12
  }
@@ -1,4 +1,3 @@
1
- import { useLocalStorage } from "@vueuse/core";
2
1
  import bus from "./bus.mjs";
3
2
  import { newCometClient } from "./comet-client.mjs";
4
3
  import { getVisitor } from "./get-visitor.mjs";
@@ -26,8 +25,6 @@ export const setToken = (newToken) => {
26
25
  export const flush = () => {
27
26
  setToken(null);
28
27
  setUser(null);
29
- const loggedIn = useLocalStorage("lin", "no");
30
- loggedIn.value = "no";
31
28
  };
32
29
  const eventHandler = (requestID, eventName) => {
33
30
  return new Promise((resolve, reject) => {
@@ -75,7 +72,7 @@ const errorHandler = (error) => {
75
72
  return new Error(message);
76
73
  };
77
74
  const optionsHandler = (options = {}, config) => {
78
- const { apiBaseURL, appClientID, appClientSecret, isMobileApp, isDesktopApp, getHostname } = config;
75
+ const { appClientID, appClientSecret, isMobileApp, isDesktopApp, getHostname } = config;
79
76
  const baseURL = "/api";
80
77
  const headers = {};
81
78
  const visitor = { platform: "web", hostname: getHostname() };
@@ -86,11 +83,11 @@ const optionsHandler = (options = {}, config) => {
86
83
  headers.authorization = `Basic ${credentials}`;
87
84
  }
88
85
  if (isMobileApp) {
89
- options.baseURL = apiBaseURL;
86
+ options.baseURL = baseURL;
90
87
  visitor.platform = "mobile";
91
88
  }
92
89
  if (isDesktopApp) {
93
- options.baseURL = apiBaseURL;
90
+ options.baseURL = baseURL;
94
91
  visitor.platform = "desktop";
95
92
  }
96
93
  if (typeof window !== "undefined") {
@@ -43,7 +43,8 @@ async function getUserRequest(fetch, config) {
43
43
  try {
44
44
  const user2 = await fetch("/account", config.useRequestHeaders?.(["cookie", "authorization"]));
45
45
  setUser(user2);
46
- return { token, user: user2 };
46
+ const token2 = getToken();
47
+ return { token: token2, user: user2 };
47
48
  } catch {
48
49
  flush();
49
50
  return { token: null, user: null };
@@ -1,6 +1,6 @@
1
1
  import { useLocalStorage } from "@vueuse/core";
2
2
  import { addRouteMiddleware, defineNuxtPlugin } from "#app";
3
- import { useRequestHeaders, useState } from "#imports";
3
+ import { useRequestHeaders, useRuntimeConfig, useState } from "#imports";
4
4
  import { fetch, getUser } from "./api/index.mjs";
5
5
  import { authMiddleware, guestMiddleware, localeMiddleware } from "./middleware/index.mjs";
6
6
  import { flush, setToken, setUser } from "./packages/api/api-client.mjs";
@@ -9,11 +9,9 @@ const useAuth = () => {
9
9
  return useState("auth", () => null);
10
10
  };
11
11
  export default defineNuxtPlugin(async (nuxtApp) => {
12
- const config = {
13
- ssr: import.meta.env.VITE_IS_SSR === "true"
14
- };
15
12
  const auth = useAuth();
16
- if (config.ssr && import.meta.server || !config.ssr) {
13
+ const runtimeConfig = useRuntimeConfig();
14
+ if (runtimeConfig.public.ssr && import.meta.server || !runtimeConfig.public.ssr) {
17
15
  flush();
18
16
  if (import.meta.server) {
19
17
  auth.value = await fetch("/account/0/authcheck", {
@@ -24,7 +22,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
24
22
  auth.value = await getUser();
25
23
  }
26
24
  }
27
- if (auth.value) {
25
+ if (auth.value?.token && auth.value?.user) {
28
26
  setToken(auth.value.token);
29
27
  setUser(auth.value.user);
30
28
  }
@@ -1,9 +1,10 @@
1
1
  import { defineNuxtPlugin } from "#app";
2
- import { useNuxtApp } from "#imports";
2
+ import { useNuxtApp, useRuntimeConfig } from "#imports";
3
3
  import { device as currentDevice } from "../packages/api/helpers/index.mjs";
4
4
  export default defineNuxtPlugin(() => {
5
5
  const device = currentDevice;
6
- const isMobileApp = import.meta.env.VITE_IS_MOBILE_APP === "true";
6
+ const runtimeConfig = useRuntimeConfig();
7
+ const isMobileApp = Boolean(runtimeConfig.public.isMobileApp);
7
8
  return {
8
9
  provide: {
9
10
  device: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inzombieland/nuxt-common",
3
- "version": "1.16.2",
3
+ "version": "1.16.4",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "exports": {