@snokam/auth 2.2.0-alpha.10 → 2.2.0-alpha.12

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/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [2.2.0-alpha.12](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.11...@snokam/auth@2.2.0-alpha.12) (2025-06-01)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * try to fix types ([eae6f94](https://github.com/snokam/components/commit/eae6f942c59dfa848d6c3b4dbf8141c2a25b3b45))
12
+
13
+
14
+
15
+
16
+
17
+ # [2.2.0-alpha.11](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.10...@snokam/auth@2.2.0-alpha.11) (2025-06-01)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * add types ([e368ad3](https://github.com/snokam/components/commit/e368ad3638b6edaff0b89335909a4c4af66991b8))
23
+
24
+
25
+
26
+
27
+
6
28
  # [2.2.0-alpha.10](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.9...@snokam/auth@2.2.0-alpha.10) (2025-06-01)
7
29
 
8
30
 
@@ -1,15 +1,5 @@
1
- import { type NextAuthMiddlewareOptions } from "next-auth/middleware";
2
- export interface BuildAuthMiddlewareOptions extends Omit<NextAuthMiddlewareOptions, "pages" | "callbacks"> {
3
- matcher?: string[];
4
- callbacks?: NextAuthMiddlewareOptions["callbacks"];
5
- protectAllRoutes?: boolean;
6
- }
7
- export declare function buildAuthMiddleware({ matcher, callbacks, protectAllRoutes, ...rest }?: BuildAuthMiddlewareOptions): {
8
- middleware: import("next-auth/middleware").NextMiddlewareWithAuth;
9
- config: {
10
- matcher: string[];
11
- };
12
- };
1
+ import { Auth } from "./utils/types";
2
+ export declare function buildAuthMiddleware({ matcher, callbacks, protectAllRoutes, ...rest }?: Auth.Middleware.Props): Auth.Middleware.Builder;
13
3
  declare const middleware: import("next-auth/middleware").NextMiddlewareWithAuth, config: {
14
4
  matcher: string[];
15
5
  };
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAgB,OAAID,IAEpBD,EAAa,OAAIC,GAClB,CATD,CASGK,MAAM,I,mBCRT,IAAIC,EAAsB,CCA1BA,EAAwB,CAACL,EAASM,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAER,EAASO,IAC5EE,OAAOC,eAAeV,EAASO,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDF,EAAwB,CAACQ,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFT,EAAyBL,IACH,oBAAXkB,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeV,EAASkB,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeV,EAAS,aAAc,CAAEoB,OAAO,GAAO,G,0ECL9D,MAAM,EAA+BC,QAAQ,kBCAvC,EAA+BA,QAAQ,wBCA7C,IAAIC,EAAkC,SAAUC,EAAGC,GAC/C,IAAIC,EAAI,CAAC,EACT,IAAK,IAAIC,KAAKH,EAAOd,OAAOM,UAAUC,eAAeC,KAAKM,EAAGG,IAAMF,EAAEG,QAAQD,GAAK,IAC9ED,EAAEC,GAAKH,EAAEG,IACb,GAAS,MAALH,GAAqD,mBAAjCd,OAAOmB,sBACtB,KAAIC,EAAI,EAAb,IAAgBH,EAAIjB,OAAOmB,sBAAsBL,GAAIM,EAAIH,EAAEI,OAAQD,IAC3DL,EAAEG,QAAQD,EAAEG,IAAM,GAAKpB,OAAOM,UAAUgB,qBAAqBd,KAAKM,EAAGG,EAAEG,MACvEJ,EAAEC,EAAEG,IAAMN,EAAEG,EAAEG,IAF4B,CAItD,OAAOJ,CACX,EAIA,MAAMO,EAAiB,CACnB,6DAEG,SAASC,EAAoBC,EAAK,CAAC,GACtC,IAAIC,GACA,QAAEC,EAAU,GAAE,UAAEC,EAAY,CAAC,EAAC,iBAAEC,GAAqBJ,EAAIK,EAAOjB,EAAOY,EAAI,CAAC,UAAW,YAAa,qBACxG,MACMM,EAAmD,YAAvCC,QAAQC,IAAIC,yBAAwC,EA8BtE,MAAO,CAAEC,YAbU,IAAAC,WAAUC,IAAD,GAAerC,OAAOsC,OAAO,CAAEC,MAAO,CAC1DC,OAAQ,eACTZ,UAAW,CACVa,WAA4C,QAA/Bf,EAAKE,EAAUa,kBAA+B,IAAPf,EAAgBA,EAAK,EAAIgB,MAAKC,YAC9E,OAnBeC,EAmBUF,EAAIG,QAAQD,WAlBzCb,GAAcF,GAA2F,KAAtEF,aAAyC,EAASA,EAAQN,SAG1FM,EAAQmB,MAAMC,IACjB,IAAKA,EACD,OAAO,EAEX,GAAIA,EAAQC,SAAS,UAAW,CAC5B,MAAMC,EAAOF,EAAQG,QAAQ,aAAc,IAC3C,OAAON,EAASO,WAAWF,EAC/B,CACA,OAAmD,KAA5C,IAAAG,OAAML,EAAS,CAAEM,KAAK,GAAtB,CAA8BT,EAAmB,QAODD,EAnBrC,IAACC,CAoBlB,IACAd,IAOYwB,OALNvB,EACT,CAAEJ,QAASJ,IACVI,aAAyC,EAASA,EAAQN,QAAU,EACjE,CAAEM,gBACF4B,EAEd,CAEA,MAAM,WAAEpB,EAAU,OAAEmB,GAAW9B,IAE/B,I","sources":["webpack://snokam/webpack/universalModuleDefinition","webpack://snokam/webpack/bootstrap","webpack://snokam/webpack/runtime/define property getters","webpack://snokam/webpack/runtime/hasOwnProperty shorthand","webpack://snokam/webpack/runtime/make namespace object","webpack://snokam/external commonjs \"path-to-regexp\"","webpack://snokam/external commonjs \"next-auth/middleware\"","webpack://snokam/./src/middleware.tsx"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"snokam\"] = factory();\n\telse\n\t\troot[\"snokam\"] = factory();\n})(this, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"path-to-regexp\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/middleware\");","var __rest = (this && this.__rest) || function (s, e) {\n var t = {};\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\n t[p] = s[p];\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\n t[p[i]] = s[p[i]];\n }\n return t;\n};\nimport { match } from \"path-to-regexp\";\nimport { withAuth, } from \"next-auth/middleware\";\n// Catch-all matcher used in Vercel preview environments\nconst previewMatcher = [\n \"/((?!api|_next/static|_next/image|favicon.ico|.*\\\\..*).*)\",\n];\nexport function buildAuthMiddleware(_a = {}) {\n var _b;\n var { matcher = [], callbacks = {}, protectAllRoutes } = _a, rest = __rest(_a, [\"matcher\", \"callbacks\", \"protectAllRoutes\"]);\n const isDev = process.env.NODE_ENV === \"development\";\n const isPreview = process.env.NEXT_PUBLIC_VERCEL_ENV === \"preview\" && !isDev;\n // Decide at runtime whether the current path should be protected\n const shouldProtectPath = (pathname) => {\n if (isPreview || (protectAllRoutes && (matcher === null || matcher === void 0 ? void 0 : matcher.length) === 0)) {\n return true;\n }\n return matcher.some((pattern) => {\n if (!pattern) {\n return false;\n }\n if (pattern.endsWith(\":path*\")) {\n const base = pattern.replace(/\\/:path\\*$/, \"\");\n return pathname.startsWith(base);\n }\n return match(pattern, { end: true })(pathname) !== false;\n });\n };\n const middleware = withAuth((_req) => { }, Object.assign({ pages: {\n signIn: \"/auth/login\",\n }, callbacks: {\n authorized: (_b = callbacks.authorized) !== null && _b !== void 0 ? _b : (({ req, token }) => {\n return shouldProtectPath(req.nextUrl.pathname) ? !!token : true;\n }),\n } }, rest));\n // Only apply matcher config if needed (to avoid enabling middleware unnecessarily)\n const config = isPreview\n ? { matcher: previewMatcher }\n : (matcher === null || matcher === void 0 ? void 0 : matcher.length) > 0\n ? { matcher }\n : undefined;\n return { middleware, config };\n}\n// Default: protect all HTML pages in preview, do nothing in production\nconst { middleware, config } = buildAuthMiddleware();\nexport { config };\nexport default middleware;\n"],"names":["root","factory","exports","module","define","amd","this","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","require","__rest","s","e","t","p","indexOf","getOwnPropertySymbols","i","length","propertyIsEnumerable","previewMatcher","buildAuthMiddleware","_a","_b","matcher","callbacks","protectAllRoutes","rest","isPreview","process","env","NEXT_PUBLIC_VERCEL_ENV","middleware","withAuth","_req","assign","pages","signIn","authorized","req","token","pathname","nextUrl","some","pattern","endsWith","base","replace","startsWith","match","end","config","undefined"],"sourceRoot":""}
1
+ {"version":3,"file":"middleware.js","mappings":"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C,EAAK,CAAC,GACtC,IAAIC,GACA,QAAEC,EAAU,GAAE,UAAEC,EAAY,CAAC,EAAC,iBAAEC,GAAqBJ,EAAIK,EAAOjB,EAAOY,EAAI,CAAC,UAAW,YAAa,qBACxG,MACMM,EAAmD,YAAvCC,QAAQC,IAAIC,yBAAwC,EA8BtE,MAAO,CAAEC,YAbU,IAAAC,WAAUC,IAAD,GAAerC,OAAOsC,OAAO,CAAEC,MAAO,CAC1DC,OAAQ,eACTZ,UAAW,CACVa,WAA4C,QAA/Bf,EAAKE,EAAUa,kBAA+B,IAAPf,EAAgBA,EAAK,EAAIgB,MAAKC,YAC9E,OAnBeC,EAmBUF,EAAIG,QAAQD,WAlBzCb,GAAcF,GAA2F,KAAtEF,aAAyC,EAASA,EAAQN,SAG1FM,EAAQmB,MAAMC,IACjB,IAAKA,EACD,OAAO,EAEX,GAAIA,EAAQC,SAAS,UAAW,CAC5B,MAAMC,EAAOF,EAAQG,QAAQ,aAAc,IAC3C,OAAON,EAASO,WAAWF,EAC/B,CACA,OAAmD,KAA5C,IAAAG,OAAML,EAAS,CAAEM,KAAK,GAAtB,CAA8BT,EAAmB,QAODD,EAnBrC,IAACC,CAoBlB,IACAd,IAOYwB,OALNvB,EACT,CAAEJ,QAASJ,IACVI,aAAyC,EAASA,EAAQN,QAAU,EACjE,CAAEM,gBACF4B,EAEd,CAEA,MAAM,WAAEpB,EAAU,OAAEmB,GAAW9B,IAE/B,I","sources":["webpack://snokam/webpack/universalModuleDefinition","webpack://snokam/webpack/bootstrap","webpack://snokam/webpack/runtime/define property getters","webpack://snokam/webpack/runtime/hasOwnProperty shorthand","webpack://snokam/webpack/runtime/make namespace object","webpack://snokam/external commonjs \"path-to-regexp\"","webpack://snokam/external commonjs \"next-auth/middleware\"","webpack://snokam/./src/middleware.tsx"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"snokam\"] = factory();\n\telse\n\t\troot[\"snokam\"] = factory();\n})(this, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"path-to-regexp\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/middleware\");","var __rest = (this && this.__rest) || function (s, e) {\n var t = {};\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)\n t[p] = s[p];\n if (s != null && typeof Object.getOwnPropertySymbols === \"function\")\n for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {\n if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))\n t[p[i]] = s[p[i]];\n }\n return t;\n};\nimport { match } from \"path-to-regexp\";\nimport { withAuth } from \"next-auth/middleware\";\n// Catch-all matcher used in Vercel preview environments\nconst previewMatcher = [\n \"/((?!api|_next/static|_next/image|favicon.ico|.*\\\\..*).*)\",\n];\nexport function buildAuthMiddleware(_a = {}) {\n var _b;\n var { matcher = [], callbacks = {}, protectAllRoutes } = _a, rest = __rest(_a, [\"matcher\", \"callbacks\", \"protectAllRoutes\"]);\n const isDev = process.env.NODE_ENV === \"development\";\n const isPreview = process.env.NEXT_PUBLIC_VERCEL_ENV === \"preview\" && !isDev;\n // Decide at runtime whether the current path should be protected\n const shouldProtectPath = (pathname) => {\n if (isPreview || (protectAllRoutes && (matcher === null || matcher === void 0 ? void 0 : matcher.length) === 0)) {\n return true;\n }\n return matcher.some((pattern) => {\n if (!pattern) {\n return false;\n }\n if (pattern.endsWith(\":path*\")) {\n const base = pattern.replace(/\\/:path\\*$/, \"\");\n return pathname.startsWith(base);\n }\n return match(pattern, { end: true })(pathname) !== false;\n });\n };\n const middleware = withAuth((_req) => { }, Object.assign({ pages: {\n signIn: \"/auth/login\",\n }, callbacks: {\n authorized: (_b = callbacks.authorized) !== null && _b !== void 0 ? _b : (({ req, token }) => {\n return shouldProtectPath(req.nextUrl.pathname) ? !!token : true;\n }),\n } }, rest));\n // Only apply matcher config if needed (to avoid enabling middleware unnecessarily)\n const config = isPreview\n ? { matcher: previewMatcher }\n : (matcher === null || matcher === void 0 ? void 0 : matcher.length) > 0\n ? { matcher }\n : undefined;\n return { middleware, config };\n}\n// Default: protect all HTML pages in preview, do nothing in production\nconst { middleware, config } = buildAuthMiddleware();\nexport { config };\nexport default middleware;\n"],"names":["root","factory","exports","module","define","amd","this","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","require","__rest","s","e","t","p","indexOf","getOwnPropertySymbols","i","length","propertyIsEnumerable","previewMatcher","buildAuthMiddleware","_a","_b","matcher","callbacks","protectAllRoutes","rest","isPreview","process","env","NEXT_PUBLIC_VERCEL_ENV","middleware","withAuth","_req","assign","pages","signIn","authorized","req","token","pathname","nextUrl","some","pattern","endsWith","base","replace","startsWith","match","end","config","undefined"],"sourceRoot":""}
@@ -1,4 +1,5 @@
1
1
  import { Session } from "next-auth";
2
+ import { NextAuthMiddlewareOptions } from "next-auth/middleware";
2
3
  import { ReactNode } from "react";
3
4
  export declare namespace Auth {
4
5
  interface Config {
@@ -22,4 +23,17 @@ export declare namespace Auth {
22
23
  showPageLoader?: boolean;
23
24
  }
24
25
  }
26
+ namespace Middleware {
27
+ interface Builder {
28
+ middleware: import("next-auth/middleware").NextMiddlewareWithAuth;
29
+ config?: {
30
+ matcher: string[];
31
+ };
32
+ }
33
+ interface Props extends Omit<NextAuthMiddlewareOptions, "pages" | "callbacks"> {
34
+ matcher?: string[];
35
+ callbacks?: NextAuthMiddlewareOptions["callbacks"];
36
+ protectAllRoutes?: boolean;
37
+ }
38
+ }
25
39
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@snokam/auth",
3
3
  "description": "Snøkam auth components",
4
- "version": "2.2.0-alpha.10",
4
+ "version": "2.2.0-alpha.12",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -67,5 +67,5 @@
67
67
  ]
68
68
  }
69
69
  },
70
- "gitHead": "db07a934b7888bb13655ff38193c79e6e653eeb8"
70
+ "gitHead": "4ad340a6c49476f19bf0fcd4790446957c26e11b"
71
71
  }