@snokam/auth 2.2.0-alpha.0 → 2.2.0-alpha.10
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 +173 -0
- package/lib/hooks.d.ts +7 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/middleware.d.ts +17 -1
- package/lib/middleware.js +1 -1
- package/lib/middleware.js.map +1 -1
- package/lib/options.js +1 -1
- package/lib/options.js.map +1 -1
- package/lib/server.js +1 -1
- package/lib/server.js.map +1 -1
- package/lib/utils/params.d.ts +1 -0
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,179 @@
|
|
|
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.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
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **auth:** update signOut function parameter name ([f5e0516](https://github.com/snokam/components/commit/f5e05166ffb60a021ca14789ea97d0e89864258f))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [2.2.0-alpha.9](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.8...@snokam/auth@2.2.0-alpha.9) (2025-06-01)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* props ([983057d](https://github.com/snokam/components/commit/983057d229e580563f909eb947c0349624504f38))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# [2.2.0-alpha.8](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.7...@snokam/auth@2.2.0-alpha.8) (2025-06-01)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Bug Fixes
|
|
32
|
+
|
|
33
|
+
* add redirectToLogin ([8de5607](https://github.com/snokam/components/commit/8de5607984fe24f1b8ca8bcb6329fc76d8d990fc))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
# [2.2.0-alpha.7](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.6...@snokam/auth@2.2.0-alpha.7) (2025-06-01)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### Bug Fixes
|
|
43
|
+
|
|
44
|
+
* add protectAllRoutes ([275bd77](https://github.com/snokam/components/commit/275bd77eb9c743548981b6647a03b1016109a1bc))
|
|
45
|
+
* protect by default ([f702d1c](https://github.com/snokam/components/commit/f702d1c2247d057d30b356a8163041a57f35c604))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
# [2.2.0-alpha.6](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.5...@snokam/auth@2.2.0-alpha.6) (2025-06-01)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
### Bug Fixes
|
|
55
|
+
|
|
56
|
+
* add util functions ([a1719ae](https://github.com/snokam/components/commit/a1719aed8b429a624d11610369d8f69d638de887))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
# [2.2.0-alpha.5](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.4...@snokam/auth@2.2.0-alpha.5) (2025-06-01)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
### Bug Fixes
|
|
66
|
+
|
|
67
|
+
* pass domain_hint ([613f8aa](https://github.com/snokam/components/commit/613f8aafe90a2cd712897a7fb018a67a2a2123ae))
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# [2.2.0-alpha.4](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.3...@snokam/auth@2.2.0-alpha.4) (2025-06-01)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
### Bug Fixes
|
|
77
|
+
|
|
78
|
+
* add credentials again ([7eaeac0](https://github.com/snokam/components/commit/7eaeac098a22ff9b57de9c8dab4982c14cb9ff83))
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
# [2.2.0-alpha.3](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.2...@snokam/auth@2.2.0-alpha.3) (2025-06-01)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
### Bug Fixes
|
|
88
|
+
|
|
89
|
+
* add dev check ([22e1dd0](https://github.com/snokam/components/commit/22e1dd0a78e34bdf9836bb61fe235e7828d83e72))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
# [2.2.0-alpha.2](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.1...@snokam/auth@2.2.0-alpha.2) (2025-06-01)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
### Bug Fixes
|
|
99
|
+
|
|
100
|
+
* middleware filter ([f49b1f2](https://github.com/snokam/components/commit/f49b1f2a15c23bc348048d3e6f13412a446518a1))
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
# [2.2.0-alpha.1](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.0...@snokam/auth@2.2.0-alpha.1) (2025-05-31)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
### Bug Fixes
|
|
110
|
+
|
|
111
|
+
* remove comment ([03d8c35](https://github.com/snokam/components/commit/03d8c35b2053164801619b76ebf627622246f7ca))
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
# [2.2.0-alpha.0](https://github.com/snokam/components/compare/@snokam/auth@2.1.4...@snokam/auth@2.2.0-alpha.0) (2025-05-31)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
### Bug Fixes
|
|
121
|
+
|
|
122
|
+
* deploy new version ([f98bb5b](https://github.com/snokam/components/commit/f98bb5b6945aa22a18948da49ace315ede23254e))
|
|
123
|
+
* login bug ([4d7f908](https://github.com/snokam/components/commit/4d7f90829585c0afd7004a992c7b841e945b5baa))
|
|
124
|
+
* trigger new release ([3af8d1b](https://github.com/snokam/components/commit/3af8d1b1803ddacb2fc1130c3194cf7191502479))
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
### Features
|
|
128
|
+
|
|
129
|
+
* **auth:** add authentication components and update dependencies ([ac51a67](https://github.com/snokam/components/commit/ac51a67fb5929df34abb04ceaa11618e0702916a))
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
## [2.1.4](https://github.com/snokam/components/compare/@snokam/auth@2.1.3...@snokam/auth@2.1.4) (2025-05-30)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
### Bug Fixes
|
|
139
|
+
|
|
140
|
+
* update storybook and all texts ([7158e03](https://github.com/snokam/components/commit/7158e03996e82cb95aac309663bbdd5c331c5579))
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
## [2.1.3](https://github.com/snokam/components/compare/@snokam/auth@2.1.2...@snokam/auth@2.1.3) (2025-05-28)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
### Bug Fixes
|
|
150
|
+
|
|
151
|
+
* browser check ([db31acd](https://github.com/snokam/components/commit/db31acd94ce5edf0e721771c004bb662cadafb53))
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
## [2.1.2](https://github.com/snokam/components/compare/@snokam/auth@2.1.1...@snokam/auth@2.1.2) (2025-05-28)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
### Bug Fixes
|
|
161
|
+
|
|
162
|
+
* hardcode snokam.no ([475d13f](https://github.com/snokam/components/commit/475d13f80128bbc68121bbd2a45bb0c97b514c35))
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
## [2.1.1](https://github.com/snokam/components/compare/@snokam/auth@2.1.0...@snokam/auth@2.1.1) (2025-05-28)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
### Bug Fixes
|
|
172
|
+
|
|
173
|
+
* add domainHint ([4fc0ae1](https://github.com/snokam/components/commit/4fc0ae1bd2a6326ad5982d5f7ad8645b5277714c))
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
6
179
|
# [2.1.0](https://github.com/snokam/components/compare/@snokam/auth@2.0.72...@snokam/auth@2.1.0) (2025-05-14)
|
|
7
180
|
|
|
8
181
|
|
package/lib/hooks.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
import { signIn } from "next-auth/react";
|
|
1
2
|
export declare function useAuth(): {
|
|
3
|
+
update: (data?: any) => Promise<import("next-auth").Session | null>;
|
|
2
4
|
getToken: (scopes: string[]) => Promise<string>;
|
|
3
5
|
isAuthenticated: boolean;
|
|
4
6
|
inProgress: boolean;
|
|
5
|
-
|
|
7
|
+
session: import("next-auth").Session;
|
|
8
|
+
signIn: typeof signIn;
|
|
9
|
+
signOut: ({ redirectTo }: {
|
|
10
|
+
redirectTo?: string;
|
|
11
|
+
}) => Promise<void>;
|
|
6
12
|
};
|
package/lib/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.snokam=t():e.snokam=t()}(this,(()=>(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.snokam=t():e.snokam=t()}(this,(()=>(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Authenticated:()=>h,Unauthenticated:()=>f,default:()=>m,middleware:()=>p(),signIn:()=>s.signIn,useAuth:()=>a});const n=require("react/jsx-runtime"),r=require("react"),o=require("next/router"),s=require("next-auth/react");var i=function(e,t,n,r){return new(n||(n=Promise))((function(o,s){function i(e){try{u(r.next(e))}catch(e){s(e)}}function a(e){try{u(r.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}u((r=r.apply(e,t||[])).next())}))};function a(){const e=(0,o.useRouter)(),{data:t,status:n,update:a}=(0,s.useSession)(),u=(0,r.useCallback)((e=>i(this,void 0,void 0,(function*(){if(!t)throw"Unable to fetch token";const n=e[0],r=yield fetch("/api/auth/token",{method:"POST",body:JSON.stringify({scope:n}),credentials:"include",headers:{"Content-Type":"application/json"}});if(401===r.status)return yield(0,s.signIn)("azure-ad"),null;if(!r.ok)throw new Error("Token fetch failed");const o=yield r.json(),{accessToken:i}=o;return`Bearer ${i}`}))),[t]);return(0,r.useMemo)((()=>({update:a,getToken:u,isAuthenticated:"authenticated"===n,inProgress:"loading"===n,session:t,signIn:s.signIn,signOut:({redirectTo:t})=>(0,s.signOut)().then((()=>{e.push(t)}))})),[a,u,n,t,s.signIn,s.signOut])}const u=require("@snokam/core"),c=(0,r.memo)((e=>{const{children:t,provider:o}=e,{inProgress:i,isAuthenticated:c}=a();return(0,r.useEffect)((()=>{i||c||(0,s.signIn)(o)}),[i,c]),c?t:(0,n.jsx)(u.PageLoader,{})})),d=(0,r.memo)((e=>{const{session:t,children:r,enforceLogin:i}=e,a=(0,o.useRouter)(),u=null==a?void 0:a.query;return(null==u?void 0:u.enforceLogin)||i?(0,n.jsx)(s.SessionProvider,{session:t,children:(0,n.jsx)(c,Object.assign({provider:"azure-ad"},e,{children:r}))}):(0,n.jsx)(s.SessionProvider,{session:t,children:r})})),l="redirect",f=({children:e})=>{const{status:t}=(0,s.useSession)();return"unauthenticated"===t?e:null},h=({children:e})=>{const{status:t}=(0,s.useSession)();return"authenticated"===t?e:null},g=require("next-auth/middleware");var p=e.n(g);const m={Login:()=>{const{isAuthenticated:e}=a(),t=(0,o.useRouter)(),[i,c]=(0,r.useState)(null);return(0,r.useEffect)((()=>{const e=new URLSearchParams(window.location.search).get("callbackUrl");c(e)}),[]),(0,r.useEffect)((()=>{var n;i&&(e?t.replace("/"):(n=i,window.sessionStorage.setItem(l,n),(0,s.signIn)("azure-ad",{callbackUrl:null!=i?i:"/"})))}),[e,i]),(0,n.jsx)(u.PageLoader,{})},Callback:()=>{const e=(0,o.useRouter)();return(0,r.useEffect)((()=>{const t=window.sessionStorage.getItem(l);t?(window.sessionStorage.removeItem(l),console.log(`Redirecting to ${t} ...`),e.replace(t)):e.replace("/")}),[e]),(0,n.jsx)(u.PageLoader,{})},Provider:d,Authenticate:c};return t})()));
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACd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OsE,OAAO,CAAEV,SAAU,YAAcF,EAAO,CAAEC,SAAUA,QAEvI,SAAK,EAAAU,gBAAiB,CAAEL,QAASA,EAASL,SAAUA,GAAW,ICZpEY,EAAoB,WCCbC,EAAkB,EAAGb,eAC9B,MAAM,OAAE1B,IAAW,IAAAC,cACnB,MAAkB,oBAAXD,EAA+B0B,EAAW,IAAI,ECF5Cc,EAAgB,EAAGd,eAC5B,MAAM,OAAE1B,IAAW,IAAAC,cACnB,MAAkB,kBAAXD,EAA6B0B,EAAW,IAAI,ECHjD,EAA+B/C,QAAQ,wB,aCS7C,SACI8D,MCFiB,KACjB,MAAM,gBAAEpB,GAAoBxB,IACtBoC,GAAS,IAAAC,cACRQ,EAAaC,IAAkB,IAAAC,UAAS,MAoB/C,OAnBA,IAAAhB,YAAU,KACN,MACMiB,EADS,IAAIC,gBAAgBC,OAAOC,SAASC,QACjC/E,IAAI,eACtByE,EAAeE,EAAG,GACnB,KACH,IAAAjB,YAAU,KLhBkB,IAACsB,EKiBpBR,IAGDrB,EACAY,EAAOkB,QAAQ,MLrBMD,EKwBJR,ELvBzBK,OAAOK,eAAeC,QAAQf,EAAmBY,IKwBzC,IAAApC,QAAO,WAAY,CACf4B,YAAaA,QAAiDA,EAAc,OAEpF,GACD,CAACrB,EAAiBqB,KACd,SAAK,EAAAb,WAAY,CAAC,EAAE,EDpB3ByB,SELoB,KACpB,MAAMrB,GAAS,IAAAC,aAYf,OAXA,IAAAN,YAAU,KACN,MAAM2B,ENJHR,OAAOK,eAAeI,QAAQlB,GMK7BiB,GNFRR,OAAOK,eAAeK,WAAWnB,GMIzBoB,QAAQC,IAAI,kBAAkBJ,SAC9BtB,EAAOkB,QAAQI,IAGftB,EAAOkB,QAAQ,IACnB,GACD,CAAClB,KACG,SAAK,EAAAJ,WAAY,CAAC,EAAE,EFP3BC,SAAQ,EACRP,aAAY,G","sources":["webpack://snokam/webpack/universalModuleDefinition","webpack://snokam/webpack/bootstrap","webpack://snokam/webpack/runtime/compat get default export","webpack://snokam/webpack/runtime/define property getters","webpack://snokam/webpack/runtime/hasOwnProperty shorthand","webpack://snokam/webpack/runtime/make namespace object","webpack://snokam/external commonjs \"react/jsx-runtime\"","webpack://snokam/external commonjs \"react\"","webpack://snokam/external commonjs \"next/router\"","webpack://snokam/external commonjs \"next-auth/react\"","webpack://snokam/./src/hooks.ts","webpack://snokam/external commonjs \"@snokam/core\"","webpack://snokam/./src/components/Provider/Authenticate.tsx","webpack://snokam/./src/components/Provider/index.tsx","webpack://snokam/./src/utils/storage.ts","webpack://snokam/./src/components/Unauthenticated.tsx","webpack://snokam/./src/components/Authenticated.tsx","webpack://snokam/external commonjs \"next-auth/middleware\"","webpack://snokam/./src/index.tsx","webpack://snokam/./src/components/Login.tsx","webpack://snokam/./src/components/Callback.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","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\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(\"react/jsx-runtime\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"react\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next/router\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/react\");","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport { useSession, signIn } from \"next-auth/react\";\nimport { useCallback, useMemo } from \"react\";\nexport function useAuth() {\n const { data: account, status } = useSession();\n const getToken = useCallback((scopes) => __awaiter(this, void 0, void 0, function* () {\n if (!account) {\n throw \"Unable to fetch token\";\n }\n const scope = scopes[0];\n const res = yield fetch(\"/api/auth/token\", {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n credentials: \"include\",\n body: JSON.stringify({ scope }),\n });\n if (res.status === 401) {\n yield signIn(\"azure-ad\");\n return null;\n }\n if (!res.ok)\n throw new Error(\"token fetch failed\");\n const token = yield res.json();\n const { accessToken } = token;\n return `Bearer ${accessToken}`;\n }), [account]);\n const value = useMemo(() => ({\n getToken,\n isAuthenticated: status === \"authenticated\",\n inProgress: status === \"loading\",\n account,\n }), [getToken, status, account]);\n return value;\n}\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@snokam/core\");","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { memo, useEffect } from \"react\";\nimport { signIn } from \"next-auth/react\";\nimport { useAuth } from \"../../hooks\";\nimport { PageLoader } from \"@snokam/core\";\nexport const Authenticate = memo((props) => {\n const { children, provider } = props;\n const { inProgress, isAuthenticated } = useAuth();\n useEffect(() => {\n if (!inProgress && !isAuthenticated) {\n signIn(provider);\n }\n }, [inProgress, isAuthenticated]);\n if (!isAuthenticated) {\n return _jsx(PageLoader, {});\n }\n return children;\n});\n","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { memo } from \"react\";\nimport { useRouter } from \"next/router\";\nimport { Authenticate } from \"./Authenticate\";\nimport { SessionProvider } from \"next-auth/react\";\nexport const Provider = memo((props) => {\n const { session, children, enforceLogin } = props;\n const router = useRouter();\n const query = router === null || router === void 0 ? void 0 : router.query;\n if ((query === null || query === void 0 ? void 0 : query.enforceLogin) || enforceLogin) {\n return (_jsx(SessionProvider, { session: session, children: _jsx(Authenticate, Object.assign({ provider: \"azure-ad\" }, props, { children: children })) }));\n }\n return _jsx(SessionProvider, { session: session, children: children });\n});\nexport default Provider;\n","const SessionStorageKey = \"redirect\";\nexport const storeCallbackUrl = (url) => {\n window.sessionStorage.setItem(SessionStorageKey, url);\n};\nexport const getStoredPath = () => {\n return window.sessionStorage.getItem(SessionStorageKey);\n};\nexport const clearStoredPath = () => {\n window.sessionStorage.removeItem(SessionStorageKey);\n};\n","import { useSession } from \"next-auth/react\";\nexport const Unauthenticated = ({ children }) => {\n const { status } = useSession();\n return status === \"unauthenticated\" ? children : null;\n};\n","import { useSession } from \"next-auth/react\";\nexport const Authenticated = ({ children }) => {\n const { status } = useSession();\n return status === \"authenticated\" ? children : null;\n};\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/middleware\");","import { Provider } from \"./components/Provider\";\nimport { Authenticate } from \"./components/Provider/Authenticate\";\nimport { Callback } from \"./components/Callback\";\nimport { Login } from \"./components/Login\";\nexport { Unauthenticated } from \"./components/Unauthenticated\";\nexport { Authenticated } from \"./components/Authenticated\";\nexport { useAuth } from \"./hooks\";\nexport { default as middleware } from \"next-auth/middleware\";\nexport { signIn } from \"next-auth/react\";\nexport default {\n Login,\n Callback,\n Provider,\n Authenticate,\n};\n","\"use client\";\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useEffect, useState } from \"react\";\nimport { useRouter } from \"next/router\";\nimport { useAuth } from \"../hooks\";\nimport { signIn } from \"next-auth/react\";\nimport { storeCallbackUrl } from \"../utils/storage\";\nimport { PageLoader } from \"@snokam/core\";\nexport const Login = () => {\n const { isAuthenticated } = useAuth();\n const router = useRouter();\n const [callbackUrl, setCallbackUrl] = useState(null);\n useEffect(() => {\n const params = new URLSearchParams(window.location.search);\n const cb = params.get(\"callbackUrl\");\n setCallbackUrl(cb);\n }, []);\n useEffect(() => {\n if (!callbackUrl) {\n return;\n }\n if (isAuthenticated) {\n router.replace(\"/\");\n }\n else {\n storeCallbackUrl(callbackUrl);\n signIn(\"azure-ad\", {\n callbackUrl: callbackUrl !== null && callbackUrl !== void 0 ? callbackUrl : \"/\",\n });\n }\n }, [isAuthenticated, callbackUrl]);\n return _jsx(PageLoader, {});\n};\nexport default Login;\n","\"use client\";\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useEffect } from \"react\";\nimport { useRouter } from \"next/router\";\nimport { clearStoredPath, getStoredPath } from \"../utils/storage\";\nimport { PageLoader } from \"@snokam/core\";\nexport const Callback = () => {\n const router = useRouter();\n useEffect(() => {\n const redirectUrl = getStoredPath();\n if (redirectUrl) {\n clearStoredPath();\n console.log(`Redirecting to ${redirectUrl} ...`);\n router.replace(redirectUrl);\n }\n else {\n router.replace(\"/\");\n }\n }, [router]);\n return _jsx(PageLoader, {});\n};\nexport default Callback;\n"],"names":["root","factory","exports","module","define","amd","this","__webpack_require__","getter","__esModule","d","a","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","require","__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","step","next","e","rejected","result","done","then","apply","useAuth","data","account","status","useSession","getToken","useCallback","scopes","scope","res","fetch","method","headers","credentials","body","JSON","stringify","signIn","ok","Error","token","json","accessToken","useMemo","isAuthenticated","inProgress","Authenticate","memo","props","children","provider","useEffect","PageLoader","Provider","session","enforceLogin","router","useRouter","query","SessionProvider","assign","SessionStorageKey","Unauthenticated","Authenticated","Login","callbackUrl","setCallbackUrl","useState","cb","URLSearchParams","window","location","search","url","replace","sessionStorage","setItem","Callback","redirectUrl","getItem","removeItem","console","log"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"index.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,EAAyBJ,IACxB,IAAIK,EAASL,GAAUA,EAAOM,WAC7B,IAAON,EAAiB,QACxB,IAAM,EAEP,OADAI,EAAoBG,EAAEF,EAAQ,CAAEG,EAAGH,IAC5BA,CAAM,ECLdD,EAAwB,CAACL,EAASU,KACjC,IAAI,IAAIC,KAAOD,EACXL,EAAoBO,EAAEF,EAAYC,KAASN,EAAoBO,EAAEZ,EAASW,IAC5EE,OAAOC,eAAed,EAASW,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDN,EAAwB,CAACY,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFb,EAAyBL,IACH,oBAAXsB,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAed,EAASsB,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAed,EAAS,aAAc,CAAEwB,OAAO,GAAO,G,kICL9D,MAAM,EAA+BC,QAAQ,qBCAvC,EAA+BA,QAAQ,SCAvC,EAA+BA,QAAQ,eCAvC,EAA+BA,QAAQ,mBCA7C,IAAIC,EAAwC,SAAUC,EAASC,EAAY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BkB,IAACmB,EKiBpBR,IAGDrB,EACA1B,EAAOwD,QAAQ,MLrBMD,EKwBJR,ELvBzBK,OAAOK,eAAeC,QAAQf,EAAmBY,IKwBzC,IAAApC,QAAO,WAAY,CACf4B,YAAaA,QAAiDA,EAAc,OAEpF,GACD,CAACrB,EAAiBqB,KACd,SAAK,EAAAV,WAAY,CAAC,EAAE,EDpB3BsB,SELoB,KACpB,MAAM3D,GAAS,IAAAC,aAYf,OAXA,IAAAmC,YAAU,KACN,MAAMwB,ENJHR,OAAOK,eAAeI,QAAQlB,GMK7BiB,GNFRR,OAAOK,eAAeK,WAAWnB,GMIzBoB,QAAQC,IAAI,kBAAkBJ,SAC9B5D,EAAOwD,QAAQI,IAGf5D,EAAOwD,QAAQ,IACnB,GACD,CAACxD,KACG,SAAK,EAAAqC,WAAY,CAAC,EAAE,EFP3BC,SAAQ,EACRP,aAAY,G","sources":["webpack://snokam/webpack/universalModuleDefinition","webpack://snokam/webpack/bootstrap","webpack://snokam/webpack/runtime/compat get default export","webpack://snokam/webpack/runtime/define property getters","webpack://snokam/webpack/runtime/hasOwnProperty shorthand","webpack://snokam/webpack/runtime/make namespace object","webpack://snokam/external commonjs \"react/jsx-runtime\"","webpack://snokam/external commonjs \"react\"","webpack://snokam/external commonjs \"next/router\"","webpack://snokam/external commonjs \"next-auth/react\"","webpack://snokam/./src/hooks.ts","webpack://snokam/external commonjs \"@snokam/core\"","webpack://snokam/./src/components/Provider/Authenticate.tsx","webpack://snokam/./src/components/Provider/index.tsx","webpack://snokam/./src/utils/storage.ts","webpack://snokam/./src/components/Unauthenticated.tsx","webpack://snokam/./src/components/Authenticated.tsx","webpack://snokam/external commonjs \"next-auth/middleware\"","webpack://snokam/./src/index.tsx","webpack://snokam/./src/components/Login.tsx","webpack://snokam/./src/components/Callback.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","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\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(\"react/jsx-runtime\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"react\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next/router\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/react\");","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport { useSession, signIn, signOut } from \"next-auth/react\";\nimport { useRouter } from \"next/router\";\nimport { useCallback, useMemo } from \"react\";\nexport function useAuth() {\n const router = useRouter();\n const { data: session, status, update } = useSession();\n const getToken = useCallback((scopes) => __awaiter(this, void 0, void 0, function* () {\n if (!session) {\n throw \"Unable to fetch token\";\n }\n const scope = scopes[0];\n const res = yield fetch(\"/api/auth/token\", {\n method: \"POST\",\n body: JSON.stringify({ scope }),\n credentials: \"include\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n });\n if (res.status === 401) {\n yield signIn(\"azure-ad\");\n return null;\n }\n if (!res.ok) {\n throw new Error(\"Token fetch failed\");\n }\n const token = yield res.json();\n const { accessToken } = token;\n return `Bearer ${accessToken}`;\n }), [session]);\n const value = useMemo(() => ({\n update,\n getToken,\n isAuthenticated: status === \"authenticated\",\n inProgress: status === \"loading\",\n session,\n signIn,\n signOut: ({ redirectTo }) => signOut().then(() => {\n router.push(redirectTo);\n }),\n }), [update, getToken, status, session, signIn, signOut]);\n return value;\n}\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@snokam/core\");","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { memo, useEffect } from \"react\";\nimport { signIn } from \"next-auth/react\";\nimport { useAuth } from \"../../hooks\";\nimport { PageLoader } from \"@snokam/core\";\nexport const Authenticate = memo((props) => {\n const { children, provider } = props;\n const { inProgress, isAuthenticated } = useAuth();\n useEffect(() => {\n if (!inProgress && !isAuthenticated) {\n signIn(provider);\n }\n }, [inProgress, isAuthenticated]);\n if (!isAuthenticated) {\n return _jsx(PageLoader, {});\n }\n return children;\n});\n","import { jsx as _jsx } from \"react/jsx-runtime\";\nimport { memo } from \"react\";\nimport { useRouter } from \"next/router\";\nimport { Authenticate } from \"./Authenticate\";\nimport { SessionProvider } from \"next-auth/react\";\nexport const Provider = memo((props) => {\n const { session, children, enforceLogin } = props;\n const router = useRouter();\n const query = router === null || router === void 0 ? void 0 : router.query;\n if ((query === null || query === void 0 ? void 0 : query.enforceLogin) || enforceLogin) {\n return (_jsx(SessionProvider, { session: session, children: _jsx(Authenticate, Object.assign({ provider: \"azure-ad\" }, props, { children: children })) }));\n }\n return _jsx(SessionProvider, { session: session, children: children });\n});\nexport default Provider;\n","const SessionStorageKey = \"redirect\";\nexport const storeCallbackUrl = (url) => {\n window.sessionStorage.setItem(SessionStorageKey, url);\n};\nexport const getStoredPath = () => {\n return window.sessionStorage.getItem(SessionStorageKey);\n};\nexport const clearStoredPath = () => {\n window.sessionStorage.removeItem(SessionStorageKey);\n};\n","import { useSession } from \"next-auth/react\";\nexport const Unauthenticated = ({ children }) => {\n const { status } = useSession();\n return status === \"unauthenticated\" ? children : null;\n};\n","import { useSession } from \"next-auth/react\";\nexport const Authenticated = ({ children }) => {\n const { status } = useSession();\n return status === \"authenticated\" ? children : null;\n};\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/middleware\");","import { Provider } from \"./components/Provider\";\nimport { Authenticate } from \"./components/Provider/Authenticate\";\nimport { Callback } from \"./components/Callback\";\nimport { Login } from \"./components/Login\";\nexport { Unauthenticated } from \"./components/Unauthenticated\";\nexport { Authenticated } from \"./components/Authenticated\";\nexport { useAuth } from \"./hooks\";\nexport { default as middleware } from \"next-auth/middleware\";\nexport { signIn } from \"next-auth/react\";\nexport default {\n Login,\n Callback,\n Provider,\n Authenticate,\n};\n","\"use client\";\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useEffect, useState } from \"react\";\nimport { useRouter } from \"next/router\";\nimport { useAuth } from \"../hooks\";\nimport { signIn } from \"next-auth/react\";\nimport { storeCallbackUrl } from \"../utils/storage\";\nimport { PageLoader } from \"@snokam/core\";\nexport const Login = () => {\n const { isAuthenticated } = useAuth();\n const router = useRouter();\n const [callbackUrl, setCallbackUrl] = useState(null);\n useEffect(() => {\n const params = new URLSearchParams(window.location.search);\n const cb = params.get(\"callbackUrl\");\n setCallbackUrl(cb);\n }, []);\n useEffect(() => {\n if (!callbackUrl) {\n return;\n }\n if (isAuthenticated) {\n router.replace(\"/\");\n }\n else {\n storeCallbackUrl(callbackUrl);\n signIn(\"azure-ad\", {\n callbackUrl: callbackUrl !== null && callbackUrl !== void 0 ? callbackUrl : \"/\",\n });\n }\n }, [isAuthenticated, callbackUrl]);\n return _jsx(PageLoader, {});\n};\nexport default Login;\n","\"use client\";\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nimport { useEffect } from \"react\";\nimport { useRouter } from \"next/router\";\nimport { clearStoredPath, getStoredPath } from \"../utils/storage\";\nimport { PageLoader } from \"@snokam/core\";\nexport const Callback = () => {\n const router = useRouter();\n useEffect(() => {\n const redirectUrl = getStoredPath();\n if (redirectUrl) {\n clearStoredPath();\n console.log(`Redirecting to ${redirectUrl} ...`);\n router.replace(redirectUrl);\n }\n else {\n router.replace(\"/\");\n }\n }, [router]);\n return _jsx(PageLoader, {});\n};\nexport default Callback;\n"],"names":["root","factory","exports","module","define","amd","this","__webpack_require__","getter","__esModule","d","a","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","require","__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","step","next","e","rejected","result","done","then","apply","useAuth","router","useRouter","data","session","status","update","useSession","getToken","useCallback","scopes","scope","res","fetch","method","body","JSON","stringify","credentials","headers","signIn","ok","Error","token","json","accessToken","useMemo","isAuthenticated","inProgress","signOut","redirectTo","push","Authenticate","memo","props","children","provider","useEffect","PageLoader","Provider","enforceLogin","query","SessionProvider","assign","SessionStorageKey","Unauthenticated","Authenticated","Login","callbackUrl","setCallbackUrl","useState","cb","URLSearchParams","window","location","search","url","replace","sessionStorage","setItem","Callback","redirectUrl","getItem","removeItem","console","log"],"sourceRoot":""}
|
package/lib/middleware.d.ts
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
|
-
|
|
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
|
+
};
|
|
13
|
+
declare const middleware: import("next-auth/middleware").NextMiddlewareWithAuth, config: {
|
|
14
|
+
matcher: string[];
|
|
15
|
+
};
|
|
16
|
+
export { config };
|
|
17
|
+
export default middleware;
|
package/lib/middleware.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.snokam=t():e.snokam=t()}(this,(()=>(()=>{"use strict";var e={
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.snokam=t():e.snokam=t()}(this,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var o in r)e.o(r,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:r[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{buildAuthMiddleware:()=>i,config:()=>c,default:()=>u});const r=require("path-to-regexp"),o=require("next-auth/middleware");var n=function(e,t){var r={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(e);n<o.length;n++)t.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(e,o[n])&&(r[o[n]]=e[o[n]])}return r};const a=["/((?!api|_next/static|_next/image|favicon.ico|.*\\..*).*)"];function i(e={}){var t,{matcher:i=[],callbacks:l={},protectAllRoutes:c}=e,u=n(e,["matcher","callbacks","protectAllRoutes"]);const p="preview"===process.env.NEXT_PUBLIC_VERCEL_ENV&&!0;return{middleware:(0,o.withAuth)((e=>{}),Object.assign({pages:{signIn:"/auth/login"},callbacks:{authorized:null!==(t=l.authorized)&&void 0!==t?t:({req:e,token:t})=>{return o=e.nextUrl.pathname,!(p||c&&0===(null==i?void 0:i.length)||i.some((e=>{if(!e)return!1;if(e.endsWith(":path*")){const t=e.replace(/\/:path\*$/,"");return o.startsWith(t)}return!1!==(0,r.match)(e,{end:!0})(o)})))||!!t;var o}}},u)),config:p?{matcher:a}:(null==i?void 0:i.length)>0?{matcher:i}:void 0}}const{middleware:l,config:c}=i(),u=l;return t})()));
|
|
2
2
|
//# sourceMappingURL=middleware.js.map
|
package/lib/middleware.js.map
CHANGED
|
@@ -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,
|
|
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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sC,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":""}
|
package/lib/options.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.snokam=t():e.snokam=t()}(this,(()=>(()=>{"use strict";var e={542:e=>{e.exports=require("next-auth")}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var a=t[o]={exports:{}};return e[o](a,a.exports,n),a.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};n.r(o),n.d(o,{default:()=>
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.snokam=t():e.snokam=t()}(this,(()=>(()=>{"use strict";var e={542:e=>{e.exports=require("next-auth")}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var a=t[o]={exports:{}};return e[o](a,a.exports,n),a.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};n.r(o),n.d(o,{default:()=>d,getNextAuthOptions:()=>u});var r=n(542),a=n.n(r);const i=require("next-auth/providers/azure-ad");var s=n.n(i);const c=()=>{const e="undefined"!=typeof window,t=e&&window.location.hostname.includes("test."),n={scope:"openid profile email offline_access https://graph.microsoft.com/User.Read"};return e&&(n.domain_hint=t?"test.snokam.no":"snokam.no"),n};const u=e=>({secret:e.nextAuthSecret,pages:{signIn:"/auth/login"},providers:[s()({clientId:e.clientId,clientSecret:e.clientSecret,tenantId:e.tenantId,authorization:{params:c()}})],callbacks:{jwt(e){return t=this,n=arguments,r=function*({token:e,account:t}){return(null==t?void 0:t.access_token)&&(e.refreshToken=t.refresh_token,e.expiresAt=t.expires_at),e},new((o=void 0)||(o=Promise))((function(e,a){function i(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(i,s)}c((r=r.apply(t,n||[])).next())}));var t,n,o,r}}}),d=e=>a()(u(e));return o})()));
|
|
2
2
|
//# sourceMappingURL=options.js.map
|
package/lib/options.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.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,kCCTTH,EAAOD,QAAUK,QAAQ,Y,GCCrBC,EAA2B,CAAC,EAGhC,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAaT,QAGrB,IAAIC,EAASK,EAAyBE,GAAY,CAGjDR,QAAS,CAAC,GAOX,OAHAW,EAAoBH,GAAUP,EAAQA,EAAOD,QAASO,GAG/CN,EAAOD,OACf,CCrBAO,EAAoBK,EAAKX,IACxB,IAAIY,EAASZ,GAAUA,EAAOa,WAC7B,IAAOb,EAAiB,QACxB,IAAM,EAEP,OADAM,EAAoBQ,EAAEF,EAAQ,CAAEG,EAAGH,IAC5BA,CAAM,ECLdN,EAAoBQ,EAAI,CAACf,EAASiB,KACjC,IAAI,IAAIC,KAAOD,EACXV,EAAoBY,EAAEF,EAAYC,KAASX,EAAoBY,EAAEnB,EAASkB,IAC5EE,OAAOC,eAAerB,EAASkB,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDX,EAAoBY,EAAI,CAACK,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFlB,EAAoBsB,EAAK7B,IACH,oBAAX8B,QAA0BA,OAAOC,aAC1CX,OAAOC,eAAerB,EAAS8B,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AASC,EAAYU,EAAGR,CAqClE,KAIZ,EAAgBhB,GAAW,IAASD,EAAmBC,I","sources":["webpack://snokam/webpack/universalModuleDefinition","webpack://snokam/external commonjs \"next-auth\"","webpack://snokam/webpack/bootstrap","webpack://snokam/webpack/runtime/compat get default export","webpack://snokam/webpack/runtime/define property getters","webpack://snokam/webpack/runtime/hasOwnProperty shorthand","webpack://snokam/webpack/runtime/make namespace object","webpack://snokam/external commonjs \"next-auth/providers/azure-ad\"","webpack://snokam/./src/utils/params.ts","webpack://snokam/./src/options.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 ","module.exports = require(\"next-auth\");","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\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(\"next-auth/providers/azure-ad\");","export const getDefaultAuthParams = () => {\n const isBrowser = typeof window !== \"undefined\";\n const isTest = isBrowser && window.location.hostname.includes(\"test.\");\n const params = {\n scope: `openid profile email offline_access https://graph.microsoft.com/User.Read`,\n };\n if (isBrowser) {\n params.domain_hint = isTest ? \"test.snokam.no\" : \"snokam.no\";\n }\n return params;\n};\n","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport NextAuth from \"next-auth\";\nimport AzureADProvider from \"next-auth/providers/azure-ad\";\nimport { getDefaultAuthParams } from \"./utils/params\";\nexport const getNextAuthOptions = (config) => {\n return {\n secret: config.nextAuthSecret,\n pages: {\n signIn: \"/auth/login\",\n },\n providers: [\n AzureADProvider({\n clientId: config.clientId,\n clientSecret: config.clientSecret,\n tenantId: config.tenantId,\n authorization: {\n params: getDefaultAuthParams(),\n },\n }),\n ],\n callbacks: {\n jwt(_a) {\n return __awaiter(this, arguments, void 0, function* ({ token, account }) {\n if (account === null || account === void 0 ? void 0 : account.access_token) {\n token.refreshToken = account.refresh_token;\n token.expiresAt = account.expires_at;\n }\n return token;\n });\n },\n },\n };\n};\nexport default (config) => NextAuth(getNextAuthOptions(config));\n"],"names":["root","factory","exports","module","define","amd","this","require","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","n","getter","__esModule","d","a","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","r","Symbol","toStringTag","value","getDefaultAuthParams","isBrowser","window","isTest","location","hostname","includes","params","scope","domain_hint","getNextAuthOptions","config","secret","nextAuthSecret","pages","signIn","providers","clientId","clientSecret","tenantId","authorization","callbacks","jwt","_a","thisArg","_arguments","arguments","generator","token","account","access_token","refreshToken","refresh_token","expiresAt","expires_at","P","Promise","resolve","reject","fulfilled","step","next","e","rejected","result","done","then","apply"],"sourceRoot":""}
|
package/lib/server.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.snokam=t():e.snokam=t()}(this,(()=>(()=>{"use strict";var e={
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.snokam=t():e.snokam=t()}(this,(()=>(()=>{"use strict";var e={542:e=>{e.exports=require("next-auth")},659:(e,t,n)=>{n.d(t,{default:()=>u,getNextAuthOptions:()=>a});var o=n(542),r=n.n(o);const i=require("next-auth/providers/azure-ad");var c=n.n(i);const s=()=>{const e="undefined"!=typeof window,t=e&&window.location.hostname.includes("test."),n={scope:"openid profile email offline_access https://graph.microsoft.com/User.Read"};return e&&(n.domain_hint=t?"test.snokam.no":"snokam.no"),n};const a=e=>({secret:e.nextAuthSecret,pages:{signIn:"/auth/login"},providers:[c()({clientId:e.clientId,clientSecret:e.clientSecret,tenantId:e.tenantId,authorization:{params:s()}})],callbacks:{jwt(e){return t=this,n=arguments,r=function*({token:e,account:t}){return(null==t?void 0:t.access_token)&&(e.refreshToken=t.refresh_token,e.expiresAt=t.expires_at),e},new((o=void 0)||(o=Promise))((function(e,i){function c(e){try{a(r.next(e))}catch(e){i(e)}}function s(e){try{a(r.throw(e))}catch(e){i(e)}}function a(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(c,s)}a((r=r.apply(t,n||[])).next())}));var t,n,o,r}}}),u=e=>r()(a(e))}},t={};function n(o){var r=t[o];if(void 0!==r)return r.exports;var i=t[o]={exports:{}};return e[o](i,i.exports,n),i.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};n.r(o),n.d(o,{default:()=>l,getServerSession:()=>u.getServerSession,getServerToken:()=>i});const r=require("@azure/msal-node");const i=e=>{return t=void 0,n=void 0,i=function*(){const{scopes:t}=e,n=new r.ConfidentialClientApplication({auth:{clientId:`${e.clientId}`,authority:`https://login.microsoftonline.com/${e.tenantId}/oauth2/v2.0`,clientSecret:`${e.secret}`}}),o=yield n.acquireTokenByClientCredential({scopes:t.map((e=>e.replace("user_impersonation",".default")))}).catch((e=>{throw console.error(e),e}));return`Bearer ${null==o?void 0:o.accessToken}`},new((o=void 0)||(o=Promise))((function(e,r){function c(e){try{a(i.next(e))}catch(e){r(e)}}function s(e){try{a(i.throw(e))}catch(e){r(e)}}function a(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(c,s)}a((i=i.apply(t,n||[])).next())}));var t,n,o,i};var c=n(659);const s=require("next-auth/jwt");var a=n(542);const u=require("next-auth/next"),l={Routes:c.default,Token:function(e){return t=this,n=void 0,i=function*(){const{req:t,res:n,authConfig:o}=e,i=yield(0,a.getServerSession)(t,n,(0,c.getNextAuthOptions)(o));if(!(null==i?void 0:i.user))return n.status(401).end("Not authenticated");if(!t.body.scope)return n.status(400).end("Invalid or missing scope");try{const{nextAuthSecret:e}=o,i=yield(0,s.getToken)({req:t,secret:e});if(!i)return n.status(500).end("Failed to get refetch token");const c=new r.ConfidentialClientApplication({auth:{clientId:o.clientId,clientSecret:o.clientSecret,authority:`https://login.microsoftonline.com/${o.tenantId}`}}),a=yield c.acquireTokenByRefreshToken({scopes:[t.body.scope],refreshToken:null==i?void 0:i.refreshToken});return a?n.status(200).json({accessToken:null==a?void 0:a.accessToken,expiresOn:Math.floor(a.expiresOn.getTime()/1e3)}):n.status(500).end("Failed to get access token")}catch(e){console.error("Token exchange error:",e),n.status(500).end("Token exchange failed")}},new((o=void 0)||(o=Promise))((function(e,r){function c(e){try{a(i.next(e))}catch(e){r(e)}}function s(e){try{a(i.throw(e))}catch(e){r(e)}}function a(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(c,s)}a((i=i.apply(t,n||[])).next())}));var t,n,o,i}};return o})()));
|
|
2
2
|
//# sourceMappingURL=server.js.map
|
package/lib/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.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,8GCTT,MAAM,EAA+BC,QAAQ,gC,aCWtC,MAAMC,EAAsBC,IAAW,CAC1CC,OAAQD,EAAOE,eACfC,MAAO,CACHC,OAAQ,eAEZC,UAAW,CACP,IAAgB,CACZC,SAAUN,EAAOM,SACjBC,aAAcP,EAAOO,aACrBC,SAAUR,EAA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,EAAmBtE,eAE7G,OAAKwE,EAGEV,EAAIK,OAAO,KAAKO,KAAK,CACxB3E,YAAayE,aAA6D,EAASA,EAAkBzE,YACrG4E,UAAWC,KAAKC,MAAML,EAAkBG,UAAUG,UAAY,OAJvDhB,EAAIK,OAAO,KAAKC,IAAI,6BAMnC,CACA,MAAOxD,GACH6C,QAAQC,MAAM,wBAAyB9C,GACvCkD,EAAIK,OAAO,KAAKC,IAAI,wBACxB,CACJ,EAlDO,KAFgEhE,OAcxC,KAZbA,EAAIC,WAAU,SAAUC,EAASC,GAC/C,SAASC,EAAUC,GAAS,IAAMC,EAAKf,EAAUgB,KAAKF,GAAS,CAAE,MAAOG,GAAKL,EAAOK,EAAI,CAAE,CAC1F,SAASC,EAASJ,GAAS,IAAMC,EAAKf,EAAiB,MAAEc,GAAS,CAAE,MAAOG,GAAKL,EAAOK,EAAI,CAAE,CAC7F,SAASF,EAAKI,GAJlB,IAAeL,EAIaK,EAAOC,KAAOT,EAAQQ,EAAOL,QAJ1CA,EAIyDK,EAAOL,MAJhDA,aAAiBL,EAAIK,EAAQ,IAAIL,GAAE,SAAUE,GAAWA,EAAQG,EAAQ,KAIjBO,KAAKR,EAAWK,EAAW,CAC7GH,GAAMf,EAAYA,EAAUsB,MAAMzB,EAASC,GAAc,KAAKkB,OAClE,IAPwC,IAAUnB,EAASC,EAAYW,EAAGT,CAqD9E,G","sources":["webpack://snokam/webpack/universalModuleDefinition","webpack://snokam/external commonjs \"next-auth/providers/azure-ad\"","webpack://snokam/./src/options.tsx","webpack://snokam/external commonjs \"next-auth\"","webpack://snokam/webpack/bootstrap","webpack://snokam/webpack/runtime/compat get default export","webpack://snokam/webpack/runtime/define property getters","webpack://snokam/webpack/runtime/hasOwnProperty shorthand","webpack://snokam/webpack/runtime/make namespace object","webpack://snokam/external commonjs \"@azure/msal-node\"","webpack://snokam/./src/server/token.tsx","webpack://snokam/external commonjs \"next-auth/jwt\"","webpack://snokam/external commonjs \"next-auth/next\"","webpack://snokam/./src/server.tsx","webpack://snokam/./src/server/handler.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 ","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/providers/azure-ad\");","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport NextAuth from \"next-auth\";\nimport AzureADProvider from \"next-auth/providers/azure-ad\";\nexport const getNextAuthOptions = (config) => ({\n secret: config.nextAuthSecret,\n pages: {\n signIn: \"/auth/login\",\n },\n providers: [\n AzureADProvider({\n clientId: config.clientId,\n clientSecret: config.clientSecret,\n tenantId: config.tenantId,\n authorization: {\n params: {\n scope: \"openid profile email offline_access https://graph.microsoft.com/User.Read\",\n },\n },\n }),\n ],\n callbacks: {\n jwt(_a) {\n return __awaiter(this, arguments, void 0, function* ({ token, account }) {\n if (account === null || account === void 0 ? void 0 : account.access_token) {\n token.accessToken = account.access_token;\n token.refreshToken = account.refresh_token;\n token.expiresAt = account.expires_at;\n }\n return token;\n });\n },\n },\n});\nexport default (config) => NextAuth(getNextAuthOptions(config));\n","module.exports = require(\"next-auth\");","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\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(\"@azure/msal-node\");","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport { ConfidentialClientApplication } from \"@azure/msal-node\";\nexport const getServerToken = (props) => __awaiter(void 0, void 0, void 0, function* () {\n const { scopes } = props;\n const cca = new ConfidentialClientApplication({\n auth: {\n clientId: `${props.clientId}`,\n authority: `https://login.microsoftonline.com/${props.tenantId}/oauth2/v2.0`,\n clientSecret: `${props.secret}`,\n },\n });\n const response = yield cca\n .acquireTokenByClientCredential({\n scopes: scopes.map((scope) => scope.replace(\"user_impersonation\", \".default\")),\n })\n .catch((e) => {\n console.error(e);\n throw e;\n });\n return `Bearer ${response === null || response === void 0 ? void 0 : response.accessToken}`;\n});\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/jwt\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/next\");","import { getServerToken } from \"./server/token\";\nimport { default as Routes } from \"./options\";\nimport { default as Token } from \"./server/handler\";\nexport { getServerToken };\nexport { getServerSession } from \"next-auth/next\";\nexport default {\n Routes,\n Token,\n};\n","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport { getToken } from \"next-auth/jwt\";\nimport { ConfidentialClientApplication } from \"@azure/msal-node\";\nimport { getServerSession } from \"next-auth\";\nimport { getNextAuthOptions } from \"../options\";\nexport default function handler(props) {\n return __awaiter(this, void 0, void 0, function* () {\n const { req, res, authConfig } = props;\n const session = yield getServerSession(req, res, getNextAuthOptions(authConfig));\n if (!(session === null || session === void 0 ? void 0 : session.user)) {\n return res.status(401).end(\"Not authenticated\");\n }\n if (!req.body.scope) {\n return res.status(400).end(\"Invalid or missing scope\");\n }\n try {\n const { nextAuthSecret } = authConfig;\n const refetchTokenResult = yield getToken({ req, secret: nextAuthSecret });\n if (!refetchTokenResult) {\n return res.status(500).end(\"Failed to get refetch token\");\n }\n const cca = new ConfidentialClientApplication({\n auth: {\n clientId: authConfig.clientId,\n clientSecret: authConfig.clientSecret,\n authority: `https://login.microsoftonline.com/${authConfig.tenantId}`,\n },\n });\n const accessTokenResult = yield cca.acquireTokenByRefreshToken({\n scopes: [req.body.scope],\n refreshToken: refetchTokenResult === null || refetchTokenResult === void 0 ? void 0 : refetchTokenResult.refreshToken,\n });\n if (!accessTokenResult) {\n return res.status(500).end(\"Failed to get access token\");\n }\n return res.status(200).json({\n accessToken: accessTokenResult === null || accessTokenResult === void 0 ? void 0 : accessTokenResult.accessToken,\n expiresOn: Math.floor(accessTokenResult.expiresOn.getTime() / 1000),\n });\n }\n catch (e) {\n console.error(\"Token exchange error:\", e);\n res.status(500).end(\"Token exchange failed\");\n }\n });\n}\n"],"names":["root","factory","exports","module","define","amd","this","require","getNextAuthOptions","config","secret","nextAuthSecret","pages","signIn","providers","clientId","clientSecret","tenantId","authorization","params","scope","callbacks","jwt","_a","thisArg","_arguments","arguments","generator","token","account","access_token","accessToken","refreshToken","refresh_token","expiresAt","expires_at","P","Promise","resolve","reject","fulfilled","value","step","next","e","rejected","result","done","then","apply","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","n","getter","__esModule","d","a","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","r","Symbol","toStringTag","getServerToken","props","__awaiter","scopes","cca","ConfidentialClientApplication","auth","authority","response","acquireTokenByClientCredential","map","replace","catch","console","error","Routes","Token","req","res","authConfig","session","getServerSession","user","status","end","body","refetchTokenResult","getToken","accessTokenResult","acquireTokenByRefreshToken","json","expiresOn","Math","floor","getTime"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"server.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9C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OAClE,IAPwC,IAAUlB,EAASC,EAAYU,EAAGR,CAqD9E,G","sources":["webpack://snokam/webpack/universalModuleDefinition","webpack://snokam/external commonjs \"next-auth\"","webpack://snokam/external commonjs \"next-auth/providers/azure-ad\"","webpack://snokam/./src/utils/params.ts","webpack://snokam/./src/options.tsx","webpack://snokam/webpack/bootstrap","webpack://snokam/webpack/runtime/compat get default export","webpack://snokam/webpack/runtime/define property getters","webpack://snokam/webpack/runtime/hasOwnProperty shorthand","webpack://snokam/webpack/runtime/make namespace object","webpack://snokam/external commonjs \"@azure/msal-node\"","webpack://snokam/./src/server/token.tsx","webpack://snokam/external commonjs \"next-auth/jwt\"","webpack://snokam/external commonjs \"next-auth/next\"","webpack://snokam/./src/server.tsx","webpack://snokam/./src/server/handler.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 ","module.exports = require(\"next-auth\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/providers/azure-ad\");","export const getDefaultAuthParams = () => {\n const isBrowser = typeof window !== \"undefined\";\n const isTest = isBrowser && window.location.hostname.includes(\"test.\");\n const params = {\n scope: `openid profile email offline_access https://graph.microsoft.com/User.Read`,\n };\n if (isBrowser) {\n params.domain_hint = isTest ? \"test.snokam.no\" : \"snokam.no\";\n }\n return params;\n};\n","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport NextAuth from \"next-auth\";\nimport AzureADProvider from \"next-auth/providers/azure-ad\";\nimport { getDefaultAuthParams } from \"./utils/params\";\nexport const getNextAuthOptions = (config) => {\n return {\n secret: config.nextAuthSecret,\n pages: {\n signIn: \"/auth/login\",\n },\n providers: [\n AzureADProvider({\n clientId: config.clientId,\n clientSecret: config.clientSecret,\n tenantId: config.tenantId,\n authorization: {\n params: getDefaultAuthParams(),\n },\n }),\n ],\n callbacks: {\n jwt(_a) {\n return __awaiter(this, arguments, void 0, function* ({ token, account }) {\n if (account === null || account === void 0 ? void 0 : account.access_token) {\n token.refreshToken = account.refresh_token;\n token.expiresAt = account.expires_at;\n }\n return token;\n });\n },\n },\n };\n};\nexport default (config) => NextAuth(getNextAuthOptions(config));\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\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(\"@azure/msal-node\");","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport { ConfidentialClientApplication } from \"@azure/msal-node\";\nexport const getServerToken = (props) => __awaiter(void 0, void 0, void 0, function* () {\n const { scopes } = props;\n const cca = new ConfidentialClientApplication({\n auth: {\n clientId: `${props.clientId}`,\n authority: `https://login.microsoftonline.com/${props.tenantId}/oauth2/v2.0`,\n clientSecret: `${props.secret}`,\n },\n });\n const response = yield cca\n .acquireTokenByClientCredential({\n scopes: scopes.map((scope) => scope.replace(\"user_impersonation\", \".default\")),\n })\n .catch((e) => {\n console.error(e);\n throw e;\n });\n return `Bearer ${response === null || response === void 0 ? void 0 : response.accessToken}`;\n});\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/jwt\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"next-auth/next\");","import { getServerToken } from \"./server/token\";\nimport { default as Routes } from \"./options\";\nimport { default as Token } from \"./server/handler\";\nexport { getServerToken };\nexport { getServerSession } from \"next-auth/next\";\nexport default {\n Routes,\n Token,\n};\n","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport { getToken } from \"next-auth/jwt\";\nimport { ConfidentialClientApplication } from \"@azure/msal-node\";\nimport { getServerSession } from \"next-auth\";\nimport { getNextAuthOptions } from \"../options\";\nexport default function handler(props) {\n return __awaiter(this, void 0, void 0, function* () {\n const { req, res, authConfig } = props;\n const session = yield getServerSession(req, res, getNextAuthOptions(authConfig));\n if (!(session === null || session === void 0 ? void 0 : session.user)) {\n return res.status(401).end(\"Not authenticated\");\n }\n if (!req.body.scope) {\n return res.status(400).end(\"Invalid or missing scope\");\n }\n try {\n const { nextAuthSecret } = authConfig;\n const refetchTokenResult = yield getToken({ req, secret: nextAuthSecret });\n if (!refetchTokenResult) {\n return res.status(500).end(\"Failed to get refetch token\");\n }\n const cca = new ConfidentialClientApplication({\n auth: {\n clientId: authConfig.clientId,\n clientSecret: authConfig.clientSecret,\n authority: `https://login.microsoftonline.com/${authConfig.tenantId}`,\n },\n });\n const accessTokenResult = yield cca.acquireTokenByRefreshToken({\n scopes: [req.body.scope],\n refreshToken: refetchTokenResult === null || refetchTokenResult === void 0 ? void 0 : refetchTokenResult.refreshToken,\n });\n if (!accessTokenResult) {\n return res.status(500).end(\"Failed to get access token\");\n }\n return res.status(200).json({\n accessToken: accessTokenResult === null || accessTokenResult === void 0 ? void 0 : accessTokenResult.accessToken,\n expiresOn: Math.floor(accessTokenResult.expiresOn.getTime() / 1000),\n });\n }\n catch (e) {\n console.error(\"Token exchange error:\", e);\n res.status(500).end(\"Token exchange failed\");\n }\n });\n}\n"],"names":["root","factory","exports","module","define","amd","this","require","getDefaultAuthParams","isBrowser","window","isTest","location","hostname","includes","params","scope","domain_hint","getNextAuthOptions","config","secret","nextAuthSecret","pages","signIn","providers","clientId","clientSecret","tenantId","authorization","callbacks","jwt","_a","thisArg","_arguments","arguments","generator","token","account","access_token","refreshToken","refresh_token","expiresAt","expires_at","P","Promise","resolve","reject","fulfilled","value","step","next","e","rejected","result","done","then","apply","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","n","getter","__esModule","d","a","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","r","Symbol","toStringTag","getServerToken","props","__awaiter","scopes","cca","ConfidentialClientApplication","auth","authority","response","acquireTokenByClientCredential","map","replace","catch","console","error","accessToken","Routes","Token","req","res","authConfig","session","getServerSession","user","status","end","body","refetchTokenResult","getToken","accessTokenResult","acquireTokenByRefreshToken","json","expiresOn","Math","floor","getTime"],"sourceRoot":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getDefaultAuthParams: () => Record<string, string>;
|
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.
|
|
4
|
+
"version": "2.2.0-alpha.10",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"@emotion/styled": "^11.14.0",
|
|
30
30
|
"@mui/material": "^7.1.0",
|
|
31
31
|
"@snokam/core": "^1.4.0",
|
|
32
|
-
"next-auth": "^4.24.11"
|
|
32
|
+
"next-auth": "^4.24.11",
|
|
33
|
+
"path-to-regexp": "^8.2.0"
|
|
33
34
|
},
|
|
34
35
|
"peerDependencies": {
|
|
35
36
|
"next": "*",
|
|
@@ -66,5 +67,5 @@
|
|
|
66
67
|
]
|
|
67
68
|
}
|
|
68
69
|
},
|
|
69
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "db07a934b7888bb13655ff38193c79e6e653eeb8"
|
|
70
71
|
}
|