@inzombieland/nuxt-common 1.16.2 → 1.16.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.
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/api/account/account.get.mjs +3 -4
- package/dist/runtime/api/account/authcheck.get.mjs +4 -5
- package/dist/runtime/api/account/default-handler.mjs +3 -4
- package/dist/runtime/api/account/middleware.mjs +2 -4
- package/dist/runtime/api/account/token.get.mjs +3 -4
- package/dist/runtime/middleware/guest.mjs +2 -1
- package/dist/runtime/middleware/locale.global.mjs +2 -6
- package/dist/runtime/plugin.mjs +3 -5
- package/dist/runtime/plugins/device.mjs +3 -2
- package/package.json +1 -1
package/dist/module.json
CHANGED
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.
|
|
5
|
+
const version = "1.16.3";
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
|
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
|
}
|
package/dist/runtime/plugin.mjs
CHANGED
|
@@ -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
|
-
|
|
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", {
|
|
@@ -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
|
|
6
|
+
const runtimeConfig = useRuntimeConfig();
|
|
7
|
+
const isMobileApp = Boolean(runtimeConfig.public.isMobileApp);
|
|
7
8
|
return {
|
|
8
9
|
provide: {
|
|
9
10
|
device: {
|