nuxt-bearer-auth 0.1.3 → 0.1.5
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.d.mts +12 -0
- package/dist/module.d.ts +12 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +12 -0
- package/dist/runtime/composables/useBearerAuth.js +14 -3
- package/dist/runtime/server/middleware/auth.js +1 -1
- package/dist/runtime/server/utils/config.js +1 -1
- package/package.json +1 -1
package/dist/module.d.mts
CHANGED
|
@@ -42,6 +42,18 @@ declare const module = defineNuxtModule({
|
|
|
42
42
|
addCsrfTokenToEventCtx: true,
|
|
43
43
|
headerName: options.csrf.headerName
|
|
44
44
|
});
|
|
45
|
+
const prefix2 = options.routes?.localApiPrefix || "/api/auth";
|
|
46
|
+
nuxt.options.routeRules = {
|
|
47
|
+
...nuxt.options.routeRules,
|
|
48
|
+
[`${prefix2}/login`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/login`] },
|
|
49
|
+
[`${prefix2}/register`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/register`] },
|
|
50
|
+
[`${prefix2}/social-login`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/social-login`] },
|
|
51
|
+
[`${prefix2}/forgot-password`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/forgot-password`] },
|
|
52
|
+
[`${prefix2}/reset-password`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/reset-password`] },
|
|
53
|
+
[`${prefix2}/otp-verification`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/otp-verification`] },
|
|
54
|
+
[`${prefix2}/resend-otp/**`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/resend-otp/**`] },
|
|
55
|
+
"/api/_csrf": { csurf: false, ...nuxt.options.routeRules?.["/api/_csrf"] }
|
|
56
|
+
};
|
|
45
57
|
}
|
|
46
58
|
addImports([
|
|
47
59
|
{
|
package/dist/module.d.ts
CHANGED
|
@@ -42,6 +42,18 @@ declare const module = defineNuxtModule({
|
|
|
42
42
|
addCsrfTokenToEventCtx: true,
|
|
43
43
|
headerName: options.csrf.headerName
|
|
44
44
|
});
|
|
45
|
+
const prefix2 = options.routes?.localApiPrefix || "/api/auth";
|
|
46
|
+
nuxt.options.routeRules = {
|
|
47
|
+
...nuxt.options.routeRules,
|
|
48
|
+
[`${prefix2}/login`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/login`] },
|
|
49
|
+
[`${prefix2}/register`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/register`] },
|
|
50
|
+
[`${prefix2}/social-login`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/social-login`] },
|
|
51
|
+
[`${prefix2}/forgot-password`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/forgot-password`] },
|
|
52
|
+
[`${prefix2}/reset-password`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/reset-password`] },
|
|
53
|
+
[`${prefix2}/otp-verification`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/otp-verification`] },
|
|
54
|
+
[`${prefix2}/resend-otp/**`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/resend-otp/**`] },
|
|
55
|
+
"/api/_csrf": { csurf: false, ...nuxt.options.routeRules?.["/api/_csrf"] }
|
|
56
|
+
};
|
|
45
57
|
}
|
|
46
58
|
addImports([
|
|
47
59
|
{
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -130,6 +130,18 @@ const module = defineNuxtModule({
|
|
|
130
130
|
addCsrfTokenToEventCtx: true,
|
|
131
131
|
headerName: options.csrf.headerName
|
|
132
132
|
});
|
|
133
|
+
const prefix2 = options.routes?.localApiPrefix || "/api/auth";
|
|
134
|
+
nuxt.options.routeRules = {
|
|
135
|
+
...nuxt.options.routeRules,
|
|
136
|
+
[`${prefix2}/login`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/login`] },
|
|
137
|
+
[`${prefix2}/register`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/register`] },
|
|
138
|
+
[`${prefix2}/social-login`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/social-login`] },
|
|
139
|
+
[`${prefix2}/forgot-password`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/forgot-password`] },
|
|
140
|
+
[`${prefix2}/reset-password`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/reset-password`] },
|
|
141
|
+
[`${prefix2}/otp-verification`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/otp-verification`] },
|
|
142
|
+
[`${prefix2}/resend-otp/**`]: { csurf: false, ...nuxt.options.routeRules?.[`${prefix2}/resend-otp/**`] },
|
|
143
|
+
"/api/_csrf": { csurf: false, ...nuxt.options.routeRules?.["/api/_csrf"] }
|
|
144
|
+
};
|
|
133
145
|
}
|
|
134
146
|
addImports([
|
|
135
147
|
{
|
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
import { navigateTo, useRuntimeConfig, useState } from "#app";
|
|
1
|
+
import { navigateTo, useNuxtApp, useRuntimeConfig, useState } from "#app";
|
|
2
2
|
import { computed, watch } from "vue";
|
|
3
3
|
import { $fetch } from "ofetch";
|
|
4
4
|
let serverCheckPromise = null;
|
|
5
5
|
let serverCheckResolve = null;
|
|
6
6
|
async function authFetch(request, options = {}) {
|
|
7
7
|
try {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
let fetcher = $fetch;
|
|
9
|
+
if (import.meta.client) {
|
|
10
|
+
try {
|
|
11
|
+
const nuxtApp = useNuxtApp();
|
|
12
|
+
const $csrfFetch = nuxtApp.$csrfFetch;
|
|
13
|
+
if ($csrfFetch) {
|
|
14
|
+
fetcher = $csrfFetch;
|
|
15
|
+
} else if (typeof useCsrf === "function") {
|
|
16
|
+
fetcher = useCsrf()?.csrfFetch || $fetch;
|
|
17
|
+
}
|
|
18
|
+
} catch {
|
|
19
|
+
}
|
|
20
|
+
}
|
|
10
21
|
return await fetcher(request, options);
|
|
11
22
|
} catch (error) {
|
|
12
23
|
throw error;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createError, defineEventHandler, getRequestURL } from "h3";
|
|
2
|
-
import { useRuntimeConfig } from "
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
3
3
|
import { getBearerAuthSession } from "../utils/sessions.js";
|
|
4
4
|
const SAFE_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS"]);
|
|
5
5
|
export default defineEventHandler(async (event) => {
|