nuxt-bearer-auth 0.1.4 → 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 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
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.12.0 || ^4.0.0"
6
6
  },
7
- "version": "0.1.4",
7
+ "version": "0.1.5",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "2.0.0"
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
- const csrf = typeof useCsrf === "function" ? useCsrf() : null;
9
- const fetcher = csrf?.csrfFetch || $fetch;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-bearer-auth",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Reusable Nuxt authentication module for bearer-token APIs with Redis sessions and CSRF protection.",
5
5
  "type": "module",
6
6
  "license": "MIT",