@snokam/auth 2.2.0-alpha.2 → 2.2.0-alpha.21

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,219 @@
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.21](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.20...@snokam/auth@2.2.0-alpha.21) (2025-06-02)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * error page ([fa7a824](https://github.com/snokam/components/commit/fa7a8240f495d4f4eb6a2418f4ec46697818b95a))
12
+
13
+
14
+
15
+
16
+
17
+ # [2.2.0-alpha.20](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.19...@snokam/auth@2.2.0-alpha.20) (2025-06-02)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * login check ([5b32b6c](https://github.com/snokam/components/commit/5b32b6c20da11fecfd9d066384c2d87c290088cd))
23
+
24
+
25
+
26
+
27
+
28
+ # [2.2.0-alpha.19](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.18...@snokam/auth@2.2.0-alpha.19) (2025-06-01)
29
+
30
+
31
+ ### Bug Fixes
32
+
33
+ * redirect issue ([8a37eb7](https://github.com/snokam/components/commit/8a37eb76ca6cc2b5d7f606a37e11aa50985972d5))
34
+
35
+
36
+
37
+
38
+
39
+ # [2.2.0-alpha.18](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.17...@snokam/auth@2.2.0-alpha.18) (2025-06-01)
40
+
41
+
42
+ ### Bug Fixes
43
+
44
+ * ssr issues ([edcf61e](https://github.com/snokam/components/commit/edcf61e73e22eb53cf591ff337d3d8c4a7d7704c))
45
+
46
+
47
+
48
+
49
+
50
+ # [2.2.0-alpha.17](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.16...@snokam/auth@2.2.0-alpha.17) (2025-06-01)
51
+
52
+
53
+ ### Bug Fixes
54
+
55
+ * add logic to throw people out ([f774304](https://github.com/snokam/components/commit/f77430428219b5fbb3f6966a45ea0b21cf494073))
56
+
57
+
58
+
59
+
60
+
61
+ # [2.2.0-alpha.16](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.15...@snokam/auth@2.2.0-alpha.16) (2025-06-01)
62
+
63
+
64
+ ### Bug Fixes
65
+
66
+ * add finally ([f112fdb](https://github.com/snokam/components/commit/f112fdb25715b52474a8f5409b5b816043e7b8bb))
67
+
68
+
69
+
70
+
71
+
72
+ # [2.2.0-alpha.15](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.14...@snokam/auth@2.2.0-alpha.15) (2025-06-01)
73
+
74
+
75
+ ### Bug Fixes
76
+
77
+ * add catch ([c489e8c](https://github.com/snokam/components/commit/c489e8c7bb24115449b19e600ab1eab73be67eb2))
78
+ * add logout wrapper ([2554cb9](https://github.com/snokam/components/commit/2554cb9974b6bc3fc8435152ccfb6f0ccc25dcbb))
79
+ * error logic on login page ([5b36d80](https://github.com/snokam/components/commit/5b36d801e33e02edc65b96d330de7df0c106431c))
80
+ * rename to error ([57874fe](https://github.com/snokam/components/commit/57874feedd3b8ebdfe2acd9e99a8f25e1a159929))
81
+
82
+
83
+
84
+
85
+
86
+ # [2.2.0-alpha.14](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.13...@snokam/auth@2.2.0-alpha.14) (2025-06-01)
87
+
88
+
89
+ ### Bug Fixes
90
+
91
+ * add error page ([b2406b4](https://github.com/snokam/components/commit/b2406b4e060c0c66f0b9584b5f30189884d6f7d8))
92
+
93
+
94
+
95
+
96
+
97
+ # [2.2.0-alpha.13](https://github.com/snokam/components/compare/@snokam/auth@2.2.0-alpha.12...@snokam/auth@2.2.0-alpha.13) (2025-06-01)
98
+
99
+
100
+ ### Bug Fixes
101
+
102
+ * pass authorizationParams ([2ea97e9](https://github.com/snokam/components/commit/2ea97e9ec7c954c7c4ea75723f8b8b157671cb62))
103
+
104
+
105
+
106
+
107
+
108
+ # [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)
109
+
110
+
111
+ ### Bug Fixes
112
+
113
+ * try to fix types ([eae6f94](https://github.com/snokam/components/commit/eae6f942c59dfa848d6c3b4dbf8141c2a25b3b45))
114
+
115
+
116
+
117
+
118
+
119
+ # [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)
120
+
121
+
122
+ ### Bug Fixes
123
+
124
+ * add types ([e368ad3](https://github.com/snokam/components/commit/e368ad3638b6edaff0b89335909a4c4af66991b8))
125
+
126
+
127
+
128
+
129
+
130
+ # [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)
131
+
132
+
133
+ ### Bug Fixes
134
+
135
+ * **auth:** update signOut function parameter name ([f5e0516](https://github.com/snokam/components/commit/f5e05166ffb60a021ca14789ea97d0e89864258f))
136
+
137
+
138
+
139
+
140
+
141
+ # [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)
142
+
143
+
144
+ ### Bug Fixes
145
+
146
+ * props ([983057d](https://github.com/snokam/components/commit/983057d229e580563f909eb947c0349624504f38))
147
+
148
+
149
+
150
+
151
+
152
+ # [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)
153
+
154
+
155
+ ### Bug Fixes
156
+
157
+ * add redirectToLogin ([8de5607](https://github.com/snokam/components/commit/8de5607984fe24f1b8ca8bcb6329fc76d8d990fc))
158
+
159
+
160
+
161
+
162
+
163
+ # [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)
164
+
165
+
166
+ ### Bug Fixes
167
+
168
+ * add protectAllRoutes ([275bd77](https://github.com/snokam/components/commit/275bd77eb9c743548981b6647a03b1016109a1bc))
169
+ * protect by default ([f702d1c](https://github.com/snokam/components/commit/f702d1c2247d057d30b356a8163041a57f35c604))
170
+
171
+
172
+
173
+
174
+
175
+ # [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)
176
+
177
+
178
+ ### Bug Fixes
179
+
180
+ * add util functions ([a1719ae](https://github.com/snokam/components/commit/a1719aed8b429a624d11610369d8f69d638de887))
181
+
182
+
183
+
184
+
185
+
186
+ # [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)
187
+
188
+
189
+ ### Bug Fixes
190
+
191
+ * pass domain_hint ([613f8aa](https://github.com/snokam/components/commit/613f8aafe90a2cd712897a7fb018a67a2a2123ae))
192
+
193
+
194
+
195
+
196
+
197
+ # [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)
198
+
199
+
200
+ ### Bug Fixes
201
+
202
+ * add credentials again ([7eaeac0](https://github.com/snokam/components/commit/7eaeac098a22ff9b57de9c8dab4982c14cb9ff83))
203
+
204
+
205
+
206
+
207
+
208
+ # [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)
209
+
210
+
211
+ ### Bug Fixes
212
+
213
+ * add dev check ([22e1dd0](https://github.com/snokam/components/commit/22e1dd0a78e34bdf9836bb61fe235e7828d83e72))
214
+
215
+
216
+
217
+
218
+
6
219
  # [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)
7
220
 
8
221
 
@@ -1,2 +1,2 @@
1
- import { Auth } from "../../utils/types";
1
+ import { Auth } from "../utils/types";
2
2
  export declare const Authenticate: import("react").MemoExoticComponent<(props: Auth.Authenticate.Props) => string | number | bigint | boolean | import("react/jsx-runtime").JSX.Element | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode>>>;
@@ -0,0 +1,5 @@
1
+ export interface ErrorPageProps {
2
+ message?: string;
3
+ }
4
+ export declare const Error: ({ message }: ErrorPageProps) => import("react/jsx-runtime").JSX.Element;
5
+ export default Error;
@@ -1,3 +1,7 @@
1
+ import { ReactNode } from "react";
1
2
  import { Auth } from "../../utils/types";
2
3
  export declare const Provider: import("react").MemoExoticComponent<(props: Auth.Provider.Props) => import("react/jsx-runtime").JSX.Element>;
4
+ export declare const Wrapper: ({ children }: {
5
+ children: ReactNode;
6
+ }) => import("react/jsx-runtime").JSX.Element;
3
7
  export default Provider;
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>;
4
+ signIn: typeof signIn;
5
+ session: import("next-auth").Session;
2
6
  getToken: (scopes: string[]) => Promise<string>;
3
- isAuthenticated: boolean;
4
7
  inProgress: boolean;
5
- account: import("next-auth").Session;
8
+ isAuthenticated: boolean;
9
+ signOut: ({ redirectTo }: {
10
+ redirectTo?: string;
11
+ }) => Promise<undefined>;
6
12
  };
package/lib/index.d.ts CHANGED
@@ -6,7 +6,7 @@ export { default as middleware } from "next-auth/middleware";
6
6
  export { signIn } from "next-auth/react";
7
7
  declare const _default: {
8
8
  Login: () => import("react/jsx-runtime").JSX.Element;
9
- Callback: () => import("react/jsx-runtime").JSX.Element;
9
+ Error: ({ message }: import("./components/Error").ErrorPageProps) => import("react/jsx-runtime").JSX.Element;
10
10
  Provider: import("react").MemoExoticComponent<(props: Auth.Provider.Props) => import("react/jsx-runtime").JSX.Element>;
11
11
  Authenticate: import("react").MemoExoticComponent<(props: Auth.Authenticate.Props) => string | number | bigint | boolean | import("react/jsx-runtime").JSX.Element | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode>>>;
12
12
  };
package/lib/index.js CHANGED
@@ -1,2 +1,42 @@
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 o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[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,{Authenticated:()=>h,Unauthenticated:()=>f,default:()=>m,middleware:()=>p(),signIn:()=>s.signIn,useAuth:()=>a});const n=require("react/jsx-runtime"),o=require("react"),r=require("next/router"),s=require("next-auth/react");var i=function(e,t,n,o){return new(n||(n=Promise))((function(r,s){function i(e){try{u(o.next(e))}catch(e){s(e)}}function a(e){try{u(o.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}u((o=o.apply(e,t||[])).next())}))};function a(){const{data:e,status:t}=(0,s.useSession)(),n=(0,o.useCallback)((t=>i(this,void 0,void 0,(function*(){if(!e)throw"Unable to fetch token";const n=t[0],o=yield fetch("/api/auth/token",{method:"POST",body:JSON.stringify({scope:n}),headers:{"Content-Type":"application/json"}});if(401===o.status)return yield(0,s.signIn)("azure-ad"),null;if(!o.ok)throw new Error("token fetch failed");const r=yield o.json(),{accessToken:i}=r;return`Bearer ${i}`}))),[e]);return(0,o.useMemo)((()=>({getToken:n,isAuthenticated:"authenticated"===t,inProgress:"loading"===t,account:e})),[n,t,e])}const u=require("@snokam/core"),c=(0,o.memo)((e=>{const{children:t,provider:r}=e,{inProgress:i,isAuthenticated:c}=a();return(0,o.useEffect)((()=>{i||c||(0,s.signIn)(r)}),[i,c]),c?t:(0,n.jsx)(u.PageLoader,{})})),d=(0,o.memo)((e=>{const{session:t,children:o,enforceLogin:i}=e,a=(0,r.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:o}))}):(0,n.jsx)(s.SessionProvider,{session:t,children:o})})),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,r.useRouter)(),[i,c]=(0,o.useState)(null);return(0,o.useEffect)((()=>{const e=new URLSearchParams(window.location.search).get("callbackUrl");c(e)}),[]),(0,o.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,r.useRouter)();return(0,o.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})()));
1
+ !function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r():"function"==typeof define&&define.amd?define([],r):"object"==typeof exports?exports.snokam=r():e.snokam=r()}(this,(()=>(()=>{"use strict";var e={n:r=>{var n=r&&r.__esModule?()=>r.default:()=>r;return e.d(n,{a:n}),n},d:(r,n)=>{for(var t in n)e.o(n,t)&&!e.o(r,t)&&Object.defineProperty(r,t,{enumerable:!0,get:n[t]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},r={};e.r(r),e.d(r,{Authenticated:()=>U,Unauthenticated:()=>I,default:()=>R,middleware:()=>_(),signIn:()=>i.signIn,useAuth:()=>a});const n=require("react/jsx-runtime"),t=require("react"),o=require("next/router"),i=require("next-auth/react");var s=function(e,r,n,t){return new(n||(n=Promise))((function(o,i){function s(e){try{l(t.next(e))}catch(e){i(e)}}function a(e){try{l(t.throw(e))}catch(e){i(e)}}function l(e){var r;e.done?o(e.value):(r=e.value,r instanceof n?r:new n((function(e){e(r)}))).then(s,a)}l((t=t.apply(e,r||[])).next())}))};function a(){const{data:e,status:r,update:n}=(0,i.useSession)(),o=e=>s(this,void 0,void 0,(function*(){const r=e[0],n=yield fetch("/api/auth/token",{method:"POST",body:JSON.stringify({scope:r}),credentials:"include",headers:{"Content-Type":"application/json"}});if(!n.ok)throw new Error("Token fetch failed");const t=yield n.json(),{accessToken:o}=t;return`Bearer ${o}`}));return(0,t.useMemo)((()=>({update:n,signIn:i.signIn,session:e,getToken:e=>o(e).catch((e=>{console.error(e),window.location.href="/auth/login?error=true"})),inProgress:"loading"===r,isAuthenticated:"authenticated"===r,signOut:e=>s(this,[e],void 0,(function*({redirectTo:e}){return(0,i.signOut)().finally((()=>{window.location.href=e}))}))})),[n,o,r,e,i.signIn,i.signOut])}const l=require("@snokam/core"),u=(0,t.memo)((e=>{const{children:r,provider:o}=e,{inProgress:s,isAuthenticated:u}=a();return(0,t.useEffect)((()=>{s||u||(0,i.signIn)(o)}),[s,u]),u?r:(0,n.jsx)(l.PageLoader,{})})),c=(0,t.memo)((e=>{const{session:r,children:t,enforceLogin:s}=e,a=(0,o.useRouter)(),l=null==a?void 0:a.query;return(null==l?void 0:l.enforceLogin)||s?(0,n.jsx)(i.SessionProvider,{session:r,children:(0,n.jsx)(u,Object.assign({provider:"azure-ad"},e,{children:t}))}):(0,n.jsx)(i.SessionProvider,{session:r,children:(0,n.jsx)(d,{children:t})})})),d=({children:e})=>{var r;const{signOut:i}=a(),s=(0,o.useRouter)();return(0,t.useEffect)((()=>{var e;"true"===(null===(e=null==s?void 0:s.query)||void 0===e?void 0:e.logout)&&i({redirectTo:"/auth/login?callbackUrl=/"})}),[null===(r=null==s?void 0:s.query)||void 0===r?void 0:r.logout]),(0,n.jsx)(n.Fragment,{children:e})},g=require("@emotion/styled");var h=e.n(g);const m=require("@snokam/core/layout");var f=e.n(m);const p=h()(f().Container)`
2
+ flex: 1;
3
+ justify-content: center;
4
+ `,x=h().div`
5
+ display: flex;
6
+ flex-direction: column;
7
+ gap: 1.5rem;
8
+ align-items: center;
9
+ width: 100%;
10
+ max-width: 600px;
11
+ padding: 2rem;
12
+ background-color: var(--color-dark-green);
13
+ border-radius: 1rem;
14
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.9);
15
+ `,v=h().h1`
16
+ font-size: 2rem;
17
+ font-weight: 600;
18
+ margin: 0;
19
+ `,j=h().img`
20
+ width: 200px;
21
+ max-width: 100%;
22
+ height: auto;
23
+ `,y=h().a`
24
+ text-decoration: underline;
25
+ color: inherit;
26
+ `,b=h()(f().Section)`
27
+ display: flex;
28
+ justify-content: center;
29
+ align-items: center;
30
+ color: var(--color-light-blue);
31
+ `,w={Container:p,Wrapper:x,Heading:v,Illustration:j,Description:h().div`
32
+ display: flex;
33
+ font-size: 1.15rem;
34
+ text-align: center;
35
+ `,Section:b,Link:y,User:h().div`
36
+ display: flex;
37
+ align-items: center;
38
+ font-size: 1rem;
39
+ margin-top: 1rem;
40
+ gap: 1rem;
41
+ `},k=require("@mui/material/Button");var S=e.n(k);const P=require("@mui/material/Alert");var q=e.n(P);let O=!1;const T=t.forwardRef((function(e,r){return O||(console.warn(["MUI: The Alert component was moved from the lab to the core.","","You should use `import { Alert } from '@mui/material'`","or `import Alert from '@mui/material/Alert'`"].join("\n")),O=!0),(0,n.jsx)(q(),{ref:r,...e})})),A=require("@mui/material"),E=({message:e})=>{const{session:r,signOut:t}=a(),o="preview"===process.env.NEXT_PUBLIC_VERCEL_ENV;return(0,n.jsx)(w.Container,{transitions:{bottom:{type:m.TransitionType.Wave}},children:(0,n.jsx)(l.Layout.Content,{children:(0,n.jsx)(w.Section,{children:(0,n.jsxs)(w.Wrapper,{children:[(0,n.jsx)(w.Heading,{children:"Oops! Noe gikk galt."}),(0,n.jsx)(w.Illustration,{src:"https://ressurser.snokam.no/figures/snowman.svg",alt:"Feil illustrasjon"}),(0,n.jsx)(w.Description,{children:null!=e?e:(0,n.jsxs)(n.Fragment,{children:["En uventet feil har oppstått.",(0,n.jsx)("br",{}),"Prøv igjen, eller logg inn på nytt."]})}),r&&(0,n.jsxs)(w.User,{children:[(0,n.jsx)(A.Avatar,{src:r.user.image}),"Logget inn som: ",r.user.name,(0,n.jsx)("br",{}),"(",r.user.email,")"]}),o&&(0,n.jsxs)(T,{severity:"warning",children:["Du er i test! Husk at det kun er mulig å logge inn ",(0,n.jsx)("br",{}),"med en av våre testbrukere som du finner i 1Password."]}),(0,n.jsx)(S(),{sx:{mt:3},color:"secondary",variant:"contained",onClick:()=>{t({redirectTo:"/auth/login?callbackUrl=/&prompt=login"})},children:"Logg inn på nytt"})]})})})})},L=E,I=({children:e})=>{const{status:r}=(0,i.useSession)();return"unauthenticated"===r?e:null},U=({children:e})=>{const{status:r}=(0,i.useSession)();return"authenticated"===r?e:null},C=require("next-auth/middleware");var _=e.n(C);const R={Login:()=>{const{isAuthenticated:e}=a(),[r,s]=(0,t.useState)(null),[u,c]=(0,t.useState)({}),[d,g]=(0,t.useState)(!1),h=(0,o.useRouter)();return(0,t.useEffect)((()=>{const e=new URLSearchParams(window.location.search);s(e.get("callbackUrl")),g(!!e.get("error"));const r={};e.forEach(((e,n)=>{"error"!==n&&"callbackUrl"!==n&&(r[n]=e)})),c(r)}),[]),(0,t.useEffect)((()=>{r&&(e?h.replace("/"):(0,i.signIn)("azure-ad",{callbackUrl:r},u))}),[e,r,u]),d?(0,n.jsx)(L,{}):(0,n.jsx)(l.PageLoader,{})},Error:E,Provider:c,Authenticate:u};return r})()));
2
42
  //# 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,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,CAAEw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AY,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 body: JSON.stringify({ scope }),\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 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","body","JSON","stringify","headers","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,IAC5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,UAAS,CAAC,IACvCG,EAASC,IAAc,IAAAJ,WAAS,GACjCjD,GAAS,IAAAC,aAuBf,OAtBA,IAAAL,YAAU,KACN,MAAM0D,EAAS,IAAIC,gBAAgBzE,OAAOC,SAASyE,QACnDR,EAAeM,EAAO9H,IAAI,gBAC1B6H,IAAaC,EAAO9H,IAAI,UACxB,MAAMiI,EAAgB,CAAC,EACvBH,EAAOI,SAAQ,CAAC1H,EAAOb,KACP,UAARA,GAA2B,gBAARA,IACnBsI,EAActI,GAAOa,EACzB,IAEJmH,EAAcM,EAAc,GAC7B,KACH,IAAA7D,YAAU,KACDmD,IAED7D,EACAc,EAAO2D,QAAQ,MAGf,IAAAjF,QAAO,WAAY,CAAEqE,eAAeG,GACxC,GACD,CAAChE,EAAiB6D,EAAaG,IAC9BE,GACO,SAAK,EAAO,CAAC,IAEjB,SAAK,EAAAvD,WAAY,CAAC,EAAE,ED3B3BxB,MAAK,EACLyB,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/Authenticate.tsx","webpack://snokam/./src/components/Provider/index.tsx","webpack://snokam/external commonjs \"@emotion/styled\"","webpack://snokam/external commonjs \"@snokam/core/layout\"","webpack://snokam/./src/components/Error/styled.tsx","webpack://snokam/external commonjs \"@mui/material/Button\"","webpack://snokam/external commonjs \"@mui/material/Alert\"","webpack://snokam/../../../node_modules/.pnpm/@mui+lab@6.0.0-beta.31_@emotion+react@11.14.0_@types+react@19.0.12_react@19.1.0__@emotion+sty_fz6gji5ey23b355xhyqlbn33ti/node_modules/@mui/lab/Alert/Alert.js","webpack://snokam/external commonjs \"@mui/material\"","webpack://snokam/./src/components/Error/index.tsx","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"],"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 { useMemo } from \"react\";\nexport function useAuth() {\n const { data: session, status, update } = useSession();\n const getToken = (scopes) => __awaiter(this, void 0, void 0, function* () {\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.ok) {\n throw new Error(\"Token fetch failed\");\n }\n const token = yield res.json();\n const { accessToken } = token;\n return `Bearer ${accessToken}`;\n });\n const value = useMemo(() => ({\n update,\n signIn,\n session,\n getToken: (scopes) => getToken(scopes).catch((error) => {\n console.error(error);\n window.location.href = \"/auth/login?error=true\";\n }),\n inProgress: status === \"loading\",\n isAuthenticated: status === \"authenticated\",\n signOut: (_a) => __awaiter(this, [_a], void 0, function* ({ redirectTo }) {\n return signOut().finally(() => {\n window.location.href = redirectTo;\n });\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, Fragment as _Fragment } from \"react/jsx-runtime\";\nimport { memo, useEffect } from \"react\";\nimport { useRouter } from \"next/router\";\nimport { Authenticate } from \"../Authenticate\";\nimport { SessionProvider } from \"next-auth/react\";\nimport { useAuth } from \"../../hooks\";\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: _jsx(Wrapper, { children: children }) }));\n});\nexport const Wrapper = ({ children }) => {\n var _a;\n const { signOut } = useAuth();\n const router = useRouter();\n useEffect(() => {\n var _a;\n if (((_a = router === null || router === void 0 ? void 0 : router.query) === null || _a === void 0 ? void 0 : _a.logout) === \"true\") {\n signOut({\n redirectTo: \"/auth/login?callbackUrl=/\",\n });\n }\n }, [(_a = router === null || router === void 0 ? void 0 : router.query) === null || _a === void 0 ? void 0 : _a.logout]);\n return _jsx(_Fragment, { children: children });\n};\nexport default Provider;\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@emotion/styled\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@snokam/core/layout\");","import styled from \"@emotion/styled\";\nimport Layout from \"@snokam/core/layout\";\nconst Container = styled(Layout.Container) `\n flex: 1;\n justify-content: center;\n`;\nconst Wrapper = styled.div `\n display: flex;\n flex-direction: column;\n gap: 1.5rem;\n align-items: center;\n width: 100%;\n max-width: 600px;\n padding: 2rem;\n background-color: var(--color-dark-green);\n border-radius: 1rem;\n box-shadow: 0 4px 10px rgba(0, 0, 0, 0.9);\n`;\nconst Heading = styled.h1 `\n font-size: 2rem;\n font-weight: 600;\n margin: 0;\n`;\nconst Illustration = styled.img `\n width: 200px;\n max-width: 100%;\n height: auto;\n`;\nconst Link = styled.a `\n text-decoration: underline;\n color: inherit;\n`;\nconst Section = styled(Layout.Section) `\n display: flex;\n justify-content: center;\n align-items: center;\n color: var(--color-light-blue);\n`;\nconst Description = styled.div `\n display: flex;\n font-size: 1.15rem;\n text-align: center;\n`;\nconst User = styled.div `\n display: flex;\n align-items: center;\n font-size: 1rem;\n margin-top: 1rem;\n gap: 1rem;\n`;\nexport default {\n Container,\n Wrapper,\n Heading,\n Illustration,\n Description,\n Section,\n Link,\n User,\n};\n","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@mui/material/Button\");","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@mui/material/Alert\");","'use client';\n\nimport * as React from 'react';\nimport Alert from '@mui/material/Alert';\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nlet warnedOnce = false;\nconst warn = () => {\n if (!warnedOnce) {\n console.warn(['MUI: The Alert component was moved from the lab to the core.', '', \"You should use `import { Alert } from '@mui/material'`\", \"or `import Alert from '@mui/material/Alert'`\"].join('\\n'));\n warnedOnce = true;\n }\n};\n\n/**\n * @ignore - do not document.\n */\nexport default /*#__PURE__*/React.forwardRef(function DeprecatedAlert(props, ref) {\n warn();\n return /*#__PURE__*/_jsx(Alert, {\n ref: ref,\n ...props\n });\n});","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@mui/material\");","import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from \"react/jsx-runtime\";\nimport Styled from \"./styled\";\nimport { Layout } from \"@snokam/core\";\nimport { TransitionType } from \"@snokam/core/layout\";\nimport { useAuth } from \"../../hooks\";\nimport Button from \"@mui/material/Button\";\nimport { Alert } from \"@mui/lab\";\nimport { Avatar } from \"@mui/material\";\nexport const Error = ({ message }) => {\n const { session, signOut } = useAuth();\n const isPreview = process.env.NEXT_PUBLIC_VERCEL_ENV === \"preview\";\n return (_jsx(Styled.Container, { transitions: {\n bottom: {\n type: TransitionType.Wave,\n },\n }, children: _jsx(Layout.Content, { children: _jsx(Styled.Section, { children: _jsxs(Styled.Wrapper, { children: [_jsx(Styled.Heading, { children: \"Oops! Noe gikk galt.\" }), _jsx(Styled.Illustration, { src: \"https://ressurser.snokam.no/figures/snowman.svg\", alt: \"Feil illustrasjon\" }), _jsx(Styled.Description, { children: message !== null && message !== void 0 ? message : (_jsxs(_Fragment, { children: [\"En uventet feil har oppst\\u00E5tt.\", _jsx(\"br\", {}), \"Pr\\u00F8v igjen, eller logg inn p\\u00E5 nytt.\"] })) }), session && (_jsxs(Styled.User, { children: [_jsx(Avatar, { src: session.user.image }), \"Logget inn som: \", session.user.name, _jsx(\"br\", {}), \"(\", session.user.email, \")\"] })), isPreview && (_jsxs(Alert, { severity: \"warning\", children: [\"Du er i test! Husk at det kun er mulig \\u00E5 logge inn \", _jsx(\"br\", {}), \"med en av v\\u00E5re testbrukere som du finner i 1Password.\"] })), _jsx(Button, { sx: { mt: 3 }, color: \"secondary\", variant: \"contained\", onClick: () => {\n signOut({\n redirectTo: \"/auth/login?callbackUrl=/&prompt=login\",\n });\n }, children: \"Logg inn p\\u00E5 nytt\" })] }) }) }) }));\n};\nexport default Error;\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/Authenticate\";\nimport { Login } from \"./components/Login\";\nimport { Error } from \"./components/Error\";\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 Error,\n Provider,\n Authenticate,\n};\n","import { 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 { PageLoader } from \"@snokam/core\";\nimport Error from \"./Error\";\nexport const Login = () => {\n const { isAuthenticated } = useAuth();\n const [callbackUrl, setCallbackUrl] = useState(null);\n const [authParams, setAuthParams] = useState({});\n const [isError, setIsError] = useState(false);\n const router = useRouter();\n useEffect(() => {\n const params = new URLSearchParams(window.location.search);\n setCallbackUrl(params.get(\"callbackUrl\"));\n setIsError(!!params.get(\"error\"));\n const authParamsObj = {};\n params.forEach((value, key) => {\n if (key !== \"error\" && key !== \"callbackUrl\") {\n authParamsObj[key] = value;\n }\n });\n setAuthParams(authParamsObj);\n }, []);\n useEffect(() => {\n if (!callbackUrl)\n return;\n if (isAuthenticated) {\n router.replace(\"/\");\n }\n else {\n signIn(\"azure-ad\", { callbackUrl }, authParams);\n }\n }, [isAuthenticated, callbackUrl, authParams]);\n if (isError) {\n return _jsx(Error, {});\n }\n return _jsx(PageLoader, {});\n};\nexport default Login;\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","session","status","update","useSession","getToken","scopes","scope","res","fetch","method","body","JSON","stringify","credentials","headers","ok","Error","token","json","accessToken","useMemo","signIn","catch","error","console","window","location","href","inProgress","isAuthenticated","signOut","_a","redirectTo","finally","Authenticate","memo","props","children","provider","useEffect","PageLoader","Provider","enforceLogin","router","useRouter","query","SessionProvider","assign","Wrapper","logout","Container","Heading","Illustration","Link","Section","Description","User","warnedOnce","ref","warn","join","message","isPreview","process","env","NEXT_PUBLIC_VERCEL_ENV","transitions","bottom","type","TransitionType","Wave","Layout","Content","src","alt","Avatar","user","image","name","email","Alert","severity","sx","mt","color","variant","onClick","Unauthenticated","Authenticated","Login","callbackUrl","setCallbackUrl","useState","authParams","setAuthParams","isError","setIsError","params","URLSearchParams","search","authParamsObj","forEach","replace"],"sourceRoot":""}
@@ -1,14 +1,5 @@
1
- import { type NextAuthMiddlewareOptions } from "next-auth/middleware";
2
- export interface BuildAuthMiddlewareOptions extends Omit<NextAuthMiddlewareOptions, "pages" | "callbacks"> {
3
- matcher?: string | string[];
4
- callbacks?: NextAuthMiddlewareOptions["callbacks"];
5
- }
6
- export declare function buildAuthMiddleware({ matcher, callbacks, ...rest }?: BuildAuthMiddlewareOptions): {
7
- middleware: import("next-auth/middleware").NextMiddlewareWithAuth;
8
- config: {
9
- matcher: string[];
10
- };
11
- };
1
+ import { Auth } from "./utils/types";
2
+ export declare function buildAuthMiddleware({ matcher, callbacks, protectAllRoutes, ...rest }?: Auth.Middleware.Props): Auth.Middleware.Builder;
12
3
  declare const middleware: import("next-auth/middleware").NextMiddlewareWithAuth, config: {
13
4
  matcher: string[];
14
5
  };
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={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:()=>l,default:()=>p});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,i,{matcher:c=[],callbacks:l={}}=e,p=n(e,["matcher","callbacks"]);const d="preview"===(null!==(t=process.env.NEXT_PUBLIC_VERCEL_ENV)&&void 0!==t?t:"development"),s=Array.isArray(c)?c:[c],u=s.length>0;return{middleware:(0,o.withAuth)((e=>{}),Object.assign({pages:{signIn:"/auth/login"},callbacks:{authorized:null!==(i=l.authorized)&&void 0!==i?i:({req:e,token:t})=>{return o=e.nextUrl.pathname,!(d||u&&s.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}}},p)),config:d?{matcher:a}:u?{matcher:s}:void 0}}const{middleware:c,config:l}=i(),p=c;return t})()));
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
@@ -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,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O,GAEEH,EAAae,MAAMC,IACtB,IAAKA,EACD,OAAO,EACX,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,IACAlB,IAOY4B,OALN3B,EACT,CAAEH,QAASL,GACXe,EACI,CAAEV,QAASO,QACXwB,EAEd,CAEA,MAAM,WAAEpB,EAAU,OAAEmB,GAAWlC,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, _c;\n var { matcher = [], callbacks = {} } = _a, rest = __rest(_a, [\"matcher\", \"callbacks\"]);\n const env = (_b = process.env.NEXT_PUBLIC_VERCEL_ENV) !== null && _b !== void 0 ? _b : \"development\";\n const isPreview = env === \"preview\";\n const matcherArray = Array.isArray(matcher) ? matcher : [matcher];\n const hasProdMatcher = matcherArray.length > 0;\n // Decide at runtime whether the current path should be protected\n const shouldProtectPath = (pathname) => {\n if (isPreview)\n return true;\n if (!hasProdMatcher)\n return false;\n return matcherArray.some((pattern) => {\n if (!pattern)\n return false;\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: (_c = callbacks.authorized) !== null && _c !== void 0 ? _c : (({ 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 : hasProdMatcher\n ? { matcher: matcherArray }\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","_c","matcher","callbacks","rest","isPreview","process","env","NEXT_PUBLIC_VERCEL_ENV","matcherArray","Array","isArray","hasProdMatcher","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":"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,0ECL9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C,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.d.ts CHANGED
@@ -1,16 +1,5 @@
1
+ import { NextAuthOptions } from "next-auth";
1
2
  import { Auth } from "./utils/types";
2
- export declare const getNextAuthOptions: (config: Auth.Config) => {
3
- secret: string;
4
- pages: {
5
- signIn: string;
6
- };
7
- providers: import("next-auth/providers").OAuthConfig<import("next-auth/providers/azure-ad").AzureADProfile>[];
8
- callbacks: {
9
- jwt({ token, account }: {
10
- token: any;
11
- account: any;
12
- }): Promise<any>;
13
- };
14
- };
3
+ export declare const getNextAuthOptions: (config: Auth.Config) => NextAuthOptions;
15
4
  declare const _default: (config: Auth.Config) => any;
16
5
  export default _default;
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(r){var o=t[r];if(void 0!==o)return o.exports;var a=t[r]={exports:{}};return e[r](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 r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},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 r={};n.r(r),n.d(r,{default:()=>u,getNextAuthOptions:()=>s});var o=n(542),a=n.n(o);const i=require("next-auth/providers/azure-ad");var c=n.n(i);const s=e=>({secret:e.nextAuthSecret,pages:{signIn:"/auth/login"},providers:[c()({clientId:e.clientId,clientSecret:e.clientSecret,tenantId:e.tenantId,authorization:{params:{scope:"openid profile email offline_access https://graph.microsoft.com/User.Read"}}})],callbacks:{jwt(e){return t=this,n=arguments,o=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((r=void 0)||(r=Promise))((function(e,a){function i(e){try{s(o.next(e))}catch(e){a(e)}}function c(e){try{s(o.throw(e))}catch(e){a(e)}}function s(t){var n;t.done?e(t.value):(n=t.value,n instanceof r?n:new r((function(e){e(n)}))).then(i,c)}s((o=o.apply(t,n||[])).next())}));var t,n,r,o}}}),u=e=>a()(s(e));return r})()));
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")},672:e=>{e.exports=require("@azure/msal-node")}},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:()=>p,getNextAuthOptions:()=>l});var r=n(542),i=n.n(r);const a=require("next-auth/providers/azure-ad");var c=n.n(a);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};var u=n(672),d=function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function a(e){try{s(o.next(e))}catch(e){i(e)}}function c(e){try{s(o.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,c)}s((o=o.apply(e,t||[])).next())}))};const l=e=>({secret:e.nextAuthSecret,pages:{signIn:"/auth/login"},providers:[c()({clientId:e.clientId,clientSecret:e.clientSecret,tenantId:e.tenantId,authorization:{params:s()}})],callbacks:{signIn(t){return d(this,arguments,void 0,(function*({account:t}){if("preview"!==process.env.NEXT_PUBLIC_VERCEL_ENV)return!0;const n=new u.ConfidentialClientApplication({auth:{clientId:e.clientId,clientSecret:e.clientSecret,authority:`https://login.microsoftonline.com/${e.tenantId}`}}),{accessToken:o}=yield n.acquireTokenByRefreshToken({scopes:[`${process.env.NEXT_PUBLIC_EMPLOYEES_API_SCOPE}`],refreshToken:null==t?void 0:t.refresh_token});return 200===(yield fetch(`${process.env.NEXT_PUBLIC_EMPLOYEES_API_BASE_URL}/v1.0/protected/me`,{headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json","Cache-Control":"no-cache, no-transform"}})).status||"/auth/login?error=true"}))},jwt(e){return d(this,arguments,void 0,(function*({token:e,account:t}){return(null==t?void 0:t.access_token)&&(e.refreshToken=t.refresh_token,e.expiresAt=t.expires_at),e}))}}}),p=e=>i()(l(e));return o})()));
2
2
  //# sourceMappingURL=options.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,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,SACjBC,cAAe,CACXC,OAAQ,CACJC,MAAO,iFAKvBC,UAAW,CACP,GAAAC,CAAIC,GACA,OA9B0CC,EA8BzB7C,KA9BkC8C,EA8B5BC,UA9B2CC,EA8BxB,WAAW,MAAEC,EAAK,QAAEC,IAK1D,OAJIA,aAAyC,EAASA,EAAQC,gBAC1DF,EAAMG,aAAeF,EAAQG,cAC7BJ,EAAMK,UAAYJ,EAAQK,YAEvBN,CACX,EAlCD,KAFgEO,OA8B7B,KA5BxBA,EAAIC,WAAU,SAAUC,EAASC,GAC/C,SAASC,EAAUhC,GAAS,IAAMiC,EAAKb,EAAUc,KAAKlC,GAAS,CAAE,MAAOmC,GAAKJ,EAAOI,EAAI,CAAE,CAC1F,SAASC,EAASpC,GAAS,IAAMiC,EAAKb,EAAiB,MAAEpB,GAAS,CAAE,MAAOmC,GAAKJ,EAAOI,EAAI,CAAE,CAC7F,SAASF,EAAKI,GAJlB,IAAerC,EAIaqC,EAAOC,KAAOR,EAAQO,EAAOrC,QAJ1CA,EAIyDqC,EAAOrC,MAJhDA,aAAiB4B,EAAI5B,EAAQ,IAAI4B,GAAE,SAAUE,GAAWA,EAAQ9B,EAAQ,KAIjBuC,KAAKP,EAAWI,EAAW,CAC7GH,GAAMb,EAAYA,EAAUoB,MAAMvB,EAASC,GAAc,KAAKgB,OAClE,IAPwC,IAAUjB,EAASC,EAAYU,EAAGR,CAqCtE,KAGR,EAAgBlB,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/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\");","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.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"],"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","getNextAuthOptions","config","secret","nextAuthSecret","pages","signIn","providers","clientId","clientSecret","tenantId","authorization","params","scope","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":""}
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,E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,6BAGjBU,QAGD,wBACX,GACJ,EACA,GAAAC,CAAIrB,GACA,OAAO7B,EAAUvC,KAAMqE,eAAW,GAAQ,WAAW,MAAEqB,EAAK,QAAEpB,IAK1D,OAJIA,aAAyC,EAASA,EAAQqB,gBAC1DD,EAAMR,aAAeZ,EAAQa,cAC7BO,EAAME,UAAYtB,EAAQuB,YAEvBH,CACX,GACJ,KAIZ,EAAgBjC,GAAW,IAASD,EAAmBC,I","sources":["webpack://snokam/webpack/universalModuleDefinition","webpack://snokam/external commonjs \"next-auth\"","webpack://snokam/external commonjs \"@azure/msal-node\"","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\");","module.exports = require(\"@azure/msal-node\");","// 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\";\nimport { ConfidentialClientApplication } from \"@azure/msal-node\";\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 signIn(_a) {\n return __awaiter(this, arguments, void 0, function* ({ account }) {\n const isPreview = process.env.NEXT_PUBLIC_VERCEL_ENV === \"preview\";\n if (!isPreview) {\n return true;\n }\n const cca = new ConfidentialClientApplication({\n auth: {\n clientId: config.clientId,\n clientSecret: config.clientSecret,\n authority: `https://login.microsoftonline.com/${config.tenantId}`,\n },\n });\n const { accessToken } = yield cca.acquireTokenByRefreshToken({\n scopes: [`${process.env.NEXT_PUBLIC_EMPLOYEES_API_SCOPE}`],\n refreshToken: account === null || account === void 0 ? void 0 : account.refresh_token,\n });\n const res = yield fetch(`${process.env.NEXT_PUBLIC_EMPLOYEES_API_BASE_URL}/v1.0/protected/me`, {\n headers: {\n Authorization: `Bearer ${accessToken}`,\n \"Content-Type\": \"application/json\",\n \"Cache-Control\": \"no-cache, no-transform\",\n },\n });\n if (res.status === 200) {\n return true;\n }\n return \"/auth/login?error=true\";\n });\n },\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","__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","step","next","e","rejected","result","done","then","apply","getNextAuthOptions","config","secret","nextAuthSecret","pages","signIn","providers","clientId","clientSecret","tenantId","authorization","callbacks","_a","arguments","account","process","env","NEXT_PUBLIC_VERCEL_ENV","cca","ConfidentialClientApplication","auth","authority","accessToken","acquireTokenByRefreshToken","scopes","NEXT_PUBLIC_EMPLOYEES_API_SCOPE","refreshToken","refresh_token","fetch","NEXT_PUBLIC_EMPLOYEES_API_BASE_URL","headers","Authorization","status","jwt","token","access_token","expiresAt","expires_at"],"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={345:(e,t,n)=>{n.d(t,{default:()=>s,getNextAuthOptions:()=>a});var o=n(542),r=n.n(o);const i=require("next-auth/providers/azure-ad");var c=n.n(i);const a=e=>({secret:e.nextAuthSecret,pages:{signIn:"/auth/login"},providers:[c()({clientId:e.clientId,clientSecret:e.clientSecret,tenantId:e.tenantId,authorization:{params:{scope:"openid profile email offline_access https://graph.microsoft.com/User.Read"}}})],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{s(r.next(e))}catch(e){i(e)}}function a(e){try{s(r.throw(e))}catch(e){i(e)}}function s(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(c,a)}s((r=r.apply(t,n||[])).next())}));var t,n,o,r}}}),s=e=>r()(a(e))},542:e=>{e.exports=require("next-auth")}},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{s(i.next(e))}catch(e){r(e)}}function a(e){try{s(i.throw(e))}catch(e){r(e)}}function s(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(c,a)}s((i=i.apply(t,n||[])).next())}));var t,n,o,i};var c=n(345);const a=require("next-auth/jwt");var s=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,s.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,a.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}`}}),s=yield c.acquireTokenByRefreshToken({scopes:[t.body.scope],refreshToken:null==i?void 0:i.refreshToken});return s?n.status(200).json({accessToken:null==s?void 0:s.accessToken,expiresOn:Math.floor(s.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{s(i.next(e))}catch(e){r(e)}}function a(e){try{s(i.throw(e))}catch(e){r(e)}}function s(t){var n;t.done?e(t.value):(n=t.value,n instanceof o?n:new o((function(e){e(n)}))).then(c,a)}s((i=i.apply(t,n||[])).next())}));var t,n,o,i}};return o})()));
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:()=>d,getNextAuthOptions:()=>l});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};var a=n(672),u=function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function c(e){try{a(o.next(e))}catch(e){i(e)}}function s(e){try{a(o.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((o=o.apply(e,t||[])).next())}))};const l=e=>({secret:e.nextAuthSecret,pages:{signIn:"/auth/login"},providers:[c()({clientId:e.clientId,clientSecret:e.clientSecret,tenantId:e.tenantId,authorization:{params:s()}})],callbacks:{signIn(t){return u(this,arguments,void 0,(function*({account:t}){if("preview"!==process.env.NEXT_PUBLIC_VERCEL_ENV)return!0;const n=new a.ConfidentialClientApplication({auth:{clientId:e.clientId,clientSecret:e.clientSecret,authority:`https://login.microsoftonline.com/${e.tenantId}`}}),{accessToken:o}=yield n.acquireTokenByRefreshToken({scopes:[`${process.env.NEXT_PUBLIC_EMPLOYEES_API_SCOPE}`],refreshToken:null==t?void 0:t.refresh_token});return 200===(yield fetch(`${process.env.NEXT_PUBLIC_EMPLOYEES_API_BASE_URL}/v1.0/protected/me`,{headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json","Cache-Control":"no-cache, no-transform"}})).status||"/auth/login?error=true"}))},jwt(e){return u(this,arguments,void 0,(function*({token:e,account:t}){return(null==t?void 0:t.access_token)&&(e.refreshToken=t.refresh_token,e.expiresAt=t.expires_at),e}))}}}),d=e=>r()(l(e))},672:e=>{e.exports=require("@azure/msal-node")}},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});var r=n(672);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,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ACe,EAAIQ,KAAKjF,OAClBW,aAAcuE,aAA+D,EAASA,EAAmBvE,eAE7G,OAAKyE,EAGEV,EAAIK,OAAO,KAAKO,KAAK,CACxBhB,YAAac,aAA6D,EAASA,EAAkBd,YACrGiB,UAAWC,KAAKC,MAAML,EAAkBG,UAAUG,UAAY,OAJvDhB,EAAIK,OAAO,KAAKC,IAAI,6BAMnC,CACA,MAAOzD,GACH6C,QAAQC,MAAM,wBAAyB9C,GACvCmD,EAAIK,OAAO,KAAKC,IAAI,wBACxB,CACJ,EAlDO,KAFgEjE,OAcxC,KAZbA,EAAIC,WAAU,SAAUC,EAASC,GAC/C,SAASC,EAAUC,GAAS,IAAMC,EAAKd,EAAUe,KAAKF,GAAS,CAAE,MAAOG,GAAKL,EAAOK,EAAI,CAAE,CAC1F,SAASC,EAASJ,GAAS,IAAMC,EAAKd,EAAiB,MAAEa,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,GAAMd,EAAYA,EAAUqB,MAAMxB,EAASC,GAAc,KAAKiB,OAClE,IAPwC,IAAUlB,EAASC,EAAYU,EAAGR,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.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","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":""}
1
+ {"version":3,"file":"server.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QA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AO,KAAKiD,IAAI,wBACxB,CACJ,EAlDO,KAFgEhG,OAcxC,KAZbA,EAAIE,WAAU,SAAUC,EAASC,GAC/C,SAASC,EAAUC,GAAS,IAAMC,EAAKN,EAAUO,KAAKF,GAAS,CAAE,MAAOG,GAAKL,EAAOK,EAAI,CAAE,CAC1F,SAASC,EAASJ,GAAS,IAAMC,EAAKN,EAAiB,MAAEK,GAAS,CAAE,MAAOG,GAAKL,EAAOK,EAAI,CAAE,CAC7F,SAASF,EAAKI,GAJlB,IAAeL,EAIaK,EAAOC,KAAOT,EAAQQ,EAAOL,QAJ1CA,EAIyDK,EAAOL,MAJhDA,aAAiBN,EAAIM,EAAQ,IAAIN,GAAE,SAAUG,GAAWA,EAAQG,EAAQ,KAIjBO,KAAKR,EAAWK,EAAW,CAC7GH,GAAMN,EAAYA,EAAUa,MAAMhB,EAASC,GAAc,KAAKS,OAClE,IAPwC,IAAUV,EAASC,EAAYC,EAAGC,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/external commonjs \"@azure/msal-node\"","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/./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\";\nimport { ConfidentialClientApplication } from \"@azure/msal-node\";\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 signIn(_a) {\n return __awaiter(this, arguments, void 0, function* ({ account }) {\n const isPreview = process.env.NEXT_PUBLIC_VERCEL_ENV === \"preview\";\n if (!isPreview) {\n return true;\n }\n const cca = new ConfidentialClientApplication({\n auth: {\n clientId: config.clientId,\n clientSecret: config.clientSecret,\n authority: `https://login.microsoftonline.com/${config.tenantId}`,\n },\n });\n const { accessToken } = yield cca.acquireTokenByRefreshToken({\n scopes: [`${process.env.NEXT_PUBLIC_EMPLOYEES_API_SCOPE}`],\n refreshToken: account === null || account === void 0 ? void 0 : account.refresh_token,\n });\n const res = yield fetch(`${process.env.NEXT_PUBLIC_EMPLOYEES_API_BASE_URL}/v1.0/protected/me`, {\n headers: {\n Authorization: `Bearer ${accessToken}`,\n \"Content-Type\": \"application/json\",\n \"Cache-Control\": \"no-cache, no-transform\",\n },\n });\n if (res.status === 200) {\n return true;\n }\n return \"/auth/login?error=true\";\n });\n },\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","module.exports = require(\"@azure/msal-node\");","// 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};","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","__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","value","step","next","e","rejected","result","done","then","apply","getNextAuthOptions","config","secret","nextAuthSecret","pages","signIn","providers","clientId","clientSecret","tenantId","authorization","callbacks","_a","arguments","account","process","env","NEXT_PUBLIC_VERCEL_ENV","cca","ConfidentialClientApplication","auth","authority","accessToken","acquireTokenByRefreshToken","scopes","NEXT_PUBLIC_EMPLOYEES_API_SCOPE","refreshToken","refresh_token","fetch","NEXT_PUBLIC_EMPLOYEES_API_BASE_URL","headers","Authorization","status","jwt","token","access_token","expiresAt","expires_at","__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","response","acquireTokenByClientCredential","map","replace","catch","console","error","Routes","Token","req","res","authConfig","session","getServerSession","user","end","body","refetchTokenResult","getToken","accessTokenResult","json","expiresOn","Math","floor","getTime"],"sourceRoot":""}
@@ -0,0 +1 @@
1
+ export declare const getDefaultAuthParams: () => Record<string, string>;
@@ -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.2",
4
+ "version": "2.2.0-alpha.21",
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": "463fa0362503c74c0ff41c0e8b5859c6549ba8a9"
70
+ "gitHead": "408b4f5dbe6b10d9388a8b73dfba6aea0fd0f4b6"
71
71
  }
@@ -1,2 +0,0 @@
1
- export declare const Callback: () => import("react/jsx-runtime").JSX.Element;
2
- export default Callback;
@@ -1,3 +0,0 @@
1
- export declare const storeCallbackUrl: (url: string) => void;
2
- export declare const getStoredPath: () => string;
3
- export declare const clearStoredPath: () => void;