@snokam/auth 2.2.10 → 2.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
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.12](https://github.com/snokam/components/compare/@snokam/auth@2.2.11...@snokam/auth@2.2.12) (2025-09-15)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * update deps ([57ee1e6](https://github.com/snokam/components/commit/57ee1e6734dfb66925fe51117ed2f1228d85d07d))
12
+
13
+
14
+
15
+
16
+
17
+ ## [2.2.11](https://github.com/snokam/components/compare/@snokam/auth@2.2.10...@snokam/auth@2.2.11) (2025-09-15)
18
+
19
+ **Note:** Version bump only for package @snokam/auth
20
+
21
+
22
+
23
+
24
+
6
25
  ## [2.2.10](https://github.com/snokam/components/compare/@snokam/auth@2.2.9...@snokam/auth@2.2.10) (2025-09-15)
7
26
 
8
27
  **Note:** Version bump only for package @snokam/auth
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
- !function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.snokam=n():e.snokam=n()}(this,(()=>(()=>{"use strict";var e={n:n=>{var r=n&&n.__esModule?()=>n.default:()=>n;return e.d(r,{a:r}),r},d:(n,r)=>{for(var t in r)e.o(r,t)&&!e.o(n,t)&&Object.defineProperty(n,t,{enumerable:!0,get:r[t]})},o:(e,n)=>Object.prototype.hasOwnProperty.call(e,n),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},n={};e.r(n),e.d(n,{Authenticated:()=>T,Unauthenticated:()=>I,default:()=>R,middleware:()=>_(),signIn:()=>i.signIn,useAuth:()=>a});const r=require("react/jsx-runtime"),t=require("react"),o=require("next/router"),i=require("next-auth/react");var s=function(e,n,r,t){return new(r||(r=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 n;e.done?o(e.value):(n=e.value,n instanceof r?n:new r((function(e){e(n)}))).then(s,a)}l((t=t.apply(e,n||[])).next())}))};function a(){const{data:e,status:n,update:r}=(0,i.useSession)(),o=e=>s(this,void 0,void 0,(function*(){const n=e[0],r=yield fetch("/api/auth/token",{method:"POST",body:JSON.stringify({scope:n}),credentials:"include",headers:{"Content-Type":"application/json"}});if(!r.ok)throw new Error("Token fetch failed");const t=yield r.json(),{accessToken:o}=t;return`Bearer ${o}`}));return(0,t.useMemo)((()=>({update:r,signIn:i.signIn,signOut:i.signOut,session:e,getToken:e=>o(e).catch((e=>{console.error(e),window.location.href="/auth/login?error=true"})),inProgress:"loading"===n,isAuthenticated:"authenticated"===n})),[r,o,n,e,i.signIn,i.signOut])}const l=require("@snokam/core"),u=(0,t.memo)((e=>{const{children:n,provider:o}=e,{inProgress:s,isAuthenticated:u}=a();return(0,t.useEffect)((()=>{s||u||(0,i.signIn)(o)}),[s,u]),u?n:(0,r.jsx)(l.PageLoader,{})})),c=(0,t.memo)((e=>{const{session:n,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,r.jsx)(i.SessionProvider,{session:n,children:(0,r.jsx)(u,Object.assign({provider:"azure-ad"},e,{children:t}))}):(0,r.jsx)(i.SessionProvider,{session:n,children:(0,r.jsx)(d,{children:t})})})),d=({children:e})=>{var n;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({callbackUrl:"/auth/login?callbackUrl=/"})}),[null===(n=null==s?void 0:s.query)||void 0===n?void 0:n.logout]),(0,r.jsx)(r.Fragment,{children:e})},g=require("@emotion/styled");var m=e.n(g);const h=require("@snokam/core/layout");var f=e.n(h);const p=m()(f().Container)`
1
+ !function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.snokam=n():e.snokam=n()}(this,(()=>(()=>{"use strict";var e={n:n=>{var t=n&&n.__esModule?()=>n.default:()=>n;return e.d(t,{a:t}),t},d:(n,t)=>{for(var r in t)e.o(t,r)&&!e.o(n,r)&&Object.defineProperty(n,r,{enumerable:!0,get:t[r]})},o:(e,n)=>Object.prototype.hasOwnProperty.call(e,n),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},n={};e.r(n),e.d(n,{Authenticated:()=>L,Unauthenticated:()=>E,default:()=>T,middleware:()=>I(),signIn:()=>i.signIn,useAuth:()=>a});const t=require("react/jsx-runtime"),r=require("react"),o=require("next/router"),i=require("next-auth/react");var s=function(e,n,t,r){return new(t||(t=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(s,a)}c((r=r.apply(e,n||[])).next())}))};function a(){const{data:e,status:n,update:t}=(0,i.useSession)(),o=e=>s(this,void 0,void 0,(function*(){const n=e[0],t=yield fetch("/api/auth/token",{method:"POST",body:JSON.stringify({scope:n}),credentials:"include",headers:{"Content-Type":"application/json"}});if(!t.ok)throw new Error("Token fetch failed");const r=yield t.json(),{accessToken:o}=r;return`Bearer ${o}`}));return(0,r.useMemo)((()=>({update:t,signIn:i.signIn,signOut:i.signOut,session:e,getToken:e=>o(e).catch((e=>{console.error(e),window.location.href="/auth/login?error=true"})),inProgress:"loading"===n,isAuthenticated:"authenticated"===n})),[t,o,n,e,i.signIn,i.signOut])}const c=require("@snokam/core"),l=(0,r.memo)((e=>{const{children:n,provider:o}=e,{inProgress:s,isAuthenticated:l}=a();return(0,r.useEffect)((()=>{s||l||(0,i.signIn)(o)}),[s,l]),l?n:(0,t.jsx)(c.PageLoader,{})})),u=(0,r.memo)((e=>{const{session:n,children:r,enforceLogin:s}=e,a=(0,o.useRouter)(),c=null==a?void 0:a.query;return(null==c?void 0:c.enforceLogin)||s?(0,t.jsx)(i.SessionProvider,{session:n,children:(0,t.jsx)(l,Object.assign({provider:"azure-ad"},e,{children:r}))}):(0,t.jsx)(i.SessionProvider,{session:n,children:(0,t.jsx)(d,{children:r})})})),d=({children:e})=>{var n;const{signOut:i}=a(),s=(0,o.useRouter)();return(0,r.useEffect)((()=>{var e;"true"===(null===(e=null==s?void 0:s.query)||void 0===e?void 0:e.logout)&&i({callbackUrl:"/auth/login?callbackUrl=/"})}),[null===(n=null==s?void 0:s.query)||void 0===n?void 0:n.logout]),(0,t.jsx)(t.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
2
  flex: 1;
3
3
  justify-content: center;
4
- `,x=m().div`
4
+ `,x=h().div`
5
5
  display: flex;
6
6
  flex-direction: column;
7
7
  gap: 1.5rem;
@@ -12,31 +12,31 @@
12
12
  background-color: var(--color-dark-green);
13
13
  border-radius: 1rem;
14
14
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.9);
15
- `,v=m().h1`
15
+ `,v=h().h1`
16
16
  font-size: 2rem;
17
17
  font-weight: 600;
18
18
  margin: 0;
19
- `,j=m().img`
19
+ `,y=h().img`
20
20
  width: 200px;
21
21
  max-width: 100%;
22
22
  height: auto;
23
- `,y=m().a`
23
+ `,j=h().a`
24
24
  text-decoration: underline;
25
25
  color: inherit;
26
- `,b=m()(f().Section)`
26
+ `,b=h()(f().Section)`
27
27
  display: flex;
28
28
  justify-content: center;
29
29
  align-items: center;
30
30
  color: var(--color-light-blue);
31
- `,k={Container:p,Wrapper:x,Heading:v,Illustration:j,Description:m().div`
31
+ `,k={Container:p,Wrapper:x,Heading:v,Illustration:y,Description:h().div`
32
32
  display: flex;
33
33
  font-size: 1.15rem;
34
34
  text-align: center;
35
- `,Section:b,Link:y,User:m().div`
35
+ `,Section:b,Link:j,User:h().div`
36
36
  display: flex;
37
37
  align-items: center;
38
38
  font-size: 1rem;
39
39
  margin-top: 1rem;
40
40
  gap: 1rem;
41
- `},w=require("@mui/material/Button");var S=e.n(w);const P=require("@mui/material/Alert");var q=e.n(P);let O=!1;const U=t.forwardRef((function(e,n){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,r.jsx)(q(),{ref:n,...e})})),A=require("@mui/material"),E=({message:e})=>{const{session:n,signOut:t}=a(),o="production"===process.env.NEXT_PUBLIC_VERCEL_ENV;return(0,r.jsx)(k.Container,{transitions:{bottom:{type:h.TransitionType.Wave}},children:(0,r.jsx)(l.Layout.Content,{children:(0,r.jsx)(k.Section,{children:(0,r.jsxs)(k.Wrapper,{children:[(0,r.jsx)(k.Heading,{children:"Oops! Noe gikk galt."}),(0,r.jsx)(k.Illustration,{src:"https://ressurser.snokam.no/figures/snowman.svg",alt:"Feil illustrasjon"}),(0,r.jsx)(k.Description,{children:null!=e?e:(0,r.jsxs)(r.Fragment,{children:["En uventet feil har oppstått.",(0,r.jsx)("br",{}),"Prøv igjen, eller logg inn på nytt."]})}),n&&(0,r.jsxs)(k.User,{children:[(0,r.jsx)(A.Avatar,{src:n.user.image}),"Logget inn som: ",n.user.name,(0,r.jsx)("br",{}),"(",n.user.email,")"]}),!o&&(0,r.jsxs)(U,{severity:"warning",children:["Du er i test! Husk at det kun er mulig å logge inn ",(0,r.jsx)("br",{}),"med en av våre testbrukere som du finner i 1Password."]}),(0,r.jsx)(S(),{sx:{mt:3},color:"secondary",variant:"contained",onClick:()=>{t({callbackUrl:"/auth/login?callbackUrl=/&prompt=login"})},children:"Logg inn på nytt"})]})})})})},L=E,I=({children:e})=>{const{status:n}=(0,i.useSession)();return"unauthenticated"===n?e:null},T=({children:e})=>{const{status:n}=(0,i.useSession)();return"authenticated"===n?e:null},C=require("next-auth/middleware");var _=e.n(C);const R={Login:()=>{const{isAuthenticated:e}=a(),[n,s]=(0,t.useState)(null),[u,c]=(0,t.useState)({}),[d,g]=(0,t.useState)(!1),m=(0,o.useRouter)();return(0,t.useEffect)((()=>{const e=new URLSearchParams(window.location.search);s(e.get("callbackUrl")),g(!!e.get("error"));const n={};e.forEach(((e,r)=>{"error"!==r&&"callbackUrl"!==r&&(n[r]=e)})),c(n)}),[]),(0,t.useEffect)((()=>{n&&(e?m.replace("/"):(0,i.signIn)("azure-ad",{callbackUrl:n},u))}),[e,n,u]),d?(0,r.jsx)(L,{}):(0,r.jsx)(l.PageLoader,{})},Error:E,Provider:c,Authenticate:u};return n})()));
41
+ `},w=require("@mui/material/Button");var S=e.n(w);const P=require("@mui/material"),O=({message:e})=>{const{session:n,signOut:r}=a(),o="production"===process.env.NEXT_PUBLIC_VERCEL_ENV;return(0,t.jsx)(k.Container,{transitions:{bottom:{type:m.TransitionType.Wave}},children:(0,t.jsx)(c.Layout.Content,{children:(0,t.jsx)(k.Section,{children:(0,t.jsxs)(k.Wrapper,{children:[(0,t.jsx)(k.Heading,{children:"Oops! Noe gikk galt."}),(0,t.jsx)(k.Illustration,{src:"https://ressurser.snokam.no/figures/snowman.svg",alt:"Feil illustrasjon"}),(0,t.jsx)(k.Description,{children:null!=e?e:(0,t.jsxs)(t.Fragment,{children:["En uventet feil har oppstått.",(0,t.jsx)("br",{}),"Prøv igjen, eller logg inn på nytt."]})}),n&&(0,t.jsxs)(k.User,{children:[(0,t.jsx)(P.Avatar,{src:n.user.image}),"Logget inn som: ",n.user.name,(0,t.jsx)("br",{}),"(",n.user.email,")"]}),!o&&(0,t.jsxs)(P.Alert,{severity:"warning",children:["Du er i test! Husk at det kun er mulig å logge inn ",(0,t.jsx)("br",{}),"med en av våre testbrukere som du finner i 1Password."]}),(0,t.jsx)(S(),{sx:{mt:3},color:"secondary",variant:"contained",onClick:()=>{r({callbackUrl:"/auth/login?callbackUrl=/&prompt=login"})},children:"Logg inn på nytt"})]})})})})},q=O,E=({children:e})=>{const{status:n}=(0,i.useSession)();return"unauthenticated"===n?e:null},L=({children:e})=>{const{status:n}=(0,i.useSession)();return"authenticated"===n?e:null},U=require("next-auth/middleware");var I=e.n(U);const T={Login:()=>{const{isAuthenticated:e}=a(),[n,s]=(0,r.useState)(null),[l,u]=(0,r.useState)({}),[d,g]=(0,r.useState)(!1),h=(0,o.useRouter)();return(0,r.useEffect)((()=>{const e=new URLSearchParams(window.location.search);s(e.get("callbackUrl")),g(!!e.get("error"));const n={};e.forEach(((e,t)=>{"error"!==t&&"callbackUrl"!==t&&(n[t]=e)})),u(n)}),[]),(0,r.useEffect)((()=>{n&&(e?h.replace("/"):(0,i.signIn)("azure-ad",{callbackUrl:n},l))}),[e,n,l]),d?(0,t.jsx)(q,{}):(0,t.jsx)(c.PageLoader,{})},Error:O,Provider:u,Authenticate:l};return n})()));
42
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,EAA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ACxB,MAAM+H,EAAgB,CAAC,EACvBH,EAAOI,SAAQ,CAACxH,EAAOb,KACP,UAARA,GAA2B,gBAARA,IACnBoI,EAAcpI,GAAOa,EACzB,IAEJiH,EAAcM,EAAc,GAC7B,KACH,IAAA9D,YAAU,KACDY,IAEDlB,EACAU,EAAO4D,QAAQ,MAGf,IAAA/E,QAAO,WAAY,CAAE2B,eAAe2C,GACxC,GACD,CAAC7D,EAAiBkB,EAAa2C,IAC9BE,GACO,SAAK,EAAO,CAAC,IAEjB,SAAK,EAAAxD,WAAY,CAAC,EAAE,ED3B3BrB,MAAK,EACLsB,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 signOut,\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 }), [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 callbackUrl: \"/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 isProd = process.env.NEXT_PUBLIC_VERCEL_ENV === \"production\";\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, \")\"] })), !isProd && (_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 callbackUrl: \"/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","signOut","catch","error","console","window","location","href","inProgress","isAuthenticated","Authenticate","memo","props","children","provider","useEffect","PageLoader","Provider","enforceLogin","router","useRouter","query","SessionProvider","assign","Wrapper","_a","logout","callbackUrl","Container","Heading","Illustration","Link","Section","Description","User","warnedOnce","ref","warn","join","message","isProd","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","setCallbackUrl","useState","authParams","setAuthParams","isError","setIsError","params","URLSearchParams","search","authParamsObj","forEach","replace"],"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,Q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OC,SAASkE,QACnDR,EAAeM,EAAOxH,IAAI,gBAC1BuH,IAAaC,EAAOxH,IAAI,UACxB,MAAM2H,EAAgB,CAAC,EACvBH,EAAOI,SAAQ,CAACpH,EAAOb,KACP,UAARA,GAA2B,gBAARA,IACnBgI,EAAchI,GAAOa,EACzB,IAEJ6G,EAAcM,EAAc,GAC7B,KACH,IAAA1D,YAAU,KACDY,IAEDlB,EACAU,EAAOwD,QAAQ,MAGf,IAAA3E,QAAO,WAAY,CAAE2B,eAAeuC,GACxC,GACD,CAACzD,EAAiBkB,EAAauC,IAC9BE,GACO,SAAK,EAAO,CAAC,IAEjB,SAAK,EAAApD,WAAY,CAAC,EAAE,ED3B3BrB,MAAK,EACLsB,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\"","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 signOut,\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 }), [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 callbackUrl: \"/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\");","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 { Avatar, Alert } from \"@mui/material\";\nexport const Error = ({ message }) => {\n const { session, signOut } = useAuth();\n const isProd = process.env.NEXT_PUBLIC_VERCEL_ENV === \"production\";\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, \")\"] })), !isProd && (_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 callbackUrl: \"/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","signOut","catch","error","console","window","location","href","inProgress","isAuthenticated","Authenticate","memo","props","children","provider","useEffect","PageLoader","Provider","enforceLogin","router","useRouter","query","SessionProvider","assign","Wrapper","_a","logout","callbackUrl","Container","Heading","Illustration","Link","Section","Description","User","message","isProd","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","setCallbackUrl","useState","authParams","setAuthParams","isError","setIsError","params","URLSearchParams","search","authParamsObj","forEach","replace"],"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={542:e=>{e.exports=require("next-auth")},672:e=>{e.exports=require("@azure/msal-node")},983:(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 s=n.n(i);const c=()=>{const e="undefined"!=typeof window,t=e&&window.location.hostname.includes("test."),n={scope:"openid profile email offline_access https://graph.microsoft.com/User.Read"};return e&&(n.domain_hint=t?"test.snokam.no":"snokam.no"),n};var a=n(672),u=function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{a(o.next(e))}catch(e){i(e)}}function c(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(s,c)}a((o=o.apply(e,t||[])).next())}))};const l=e=>{const{name:t,domain:n,secure:o}=function(e){const{hostname:t,protocol:n}=new URL(e),o="https:"===n,r=o?"__Secure-":"",{tag:i,domain:s}=(()=>{if("localhost"===t||/^[\d.]+$/.test(t))return{tag:"local"};if(t.endsWith(".test.snokam.no"))return{tag:"test",domain:".test.snokam.no"};if(t.endsWith(".snokam.no"))return{tag:"prod",domain:".snokam.no"};const e=t.split(".");if(e.length>=2){const t=e.slice(-2).join(".");return{tag:t.replace(/\./g,"-"),domain:`.${t}`}}return{tag:"host"}})();return{name:`${r}next-auth.${i}.session-token`,domain:s,secure:o}}(process.env.NEXTAUTH_URL);return{secret:e.nextAuthSecret,pages:{signIn:"/auth/login"},providers:[s()({clientId:e.clientId,clientSecret:e.clientSecret,tenantId:e.tenantId,authorization:{params:c()}})],cookies:{sessionToken:{name:t,options:{path:"/",httpOnly:!0,sameSite:"lax",secure:o,domain:n}}},callbacks:{signIn(t){return u(this,arguments,void 0,(function*({account:t}){if("production"===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))}},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 s(e){try{a(i.next(e))}catch(e){r(e)}}function c(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(s,c)}a((i=i.apply(t,n||[])).next())}));var t,n,o,i};var s=n(983);const c=require("next-auth/jwt");var a=n(542);const u=require("next-auth/next"),l={Routes:s.default,Token:function(e){return t=this,n=void 0,i=function*(){const{req:t,res:n,authConfig:o}=e,i=(0,s.getNextAuthOptions)(o),u=yield(0,a.getServerSession)(t,n,i);if(!(null==u?void 0:u.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,s=yield(0,c.getToken)({req:t,secret:e,cookieName:i.cookies.sessionToken.name});if(!s)return n.status(500).end("Failed to get refetch token");const a=new r.ConfidentialClientApplication({auth:{clientId:o.clientId,clientSecret:o.clientSecret,authority:`https://login.microsoftonline.com/${o.tenantId}`}}),u=yield a.acquireTokenByRefreshToken({scopes:[t.body.scope],refreshToken:null==s?void 0:s.refreshToken});return u?n.status(200).json({accessToken:null==u?void 0:u.accessToken,expiresOn:Math.floor(u.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 s(e){try{a(i.next(e))}catch(e){r(e)}}function c(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(s,c)}a((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={333:(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 s=n.n(i);const c=()=>{const e="undefined"!=typeof window,t=e&&window.location.hostname.includes("test."),n={scope:"openid profile email offline_access https://graph.microsoft.com/User.Read"};return e&&(n.domain_hint=t?"test.snokam.no":"snokam.no"),n};var a=n(672),u=function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{a(o.next(e))}catch(e){i(e)}}function c(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(s,c)}a((o=o.apply(e,t||[])).next())}))};const l=e=>{const{name:t,domain:n,secure:o}=function(e){const{hostname:t,protocol:n}=new URL(e),o="https:"===n,r=o?"__Secure-":"",{tag:i,domain:s}=(()=>{if("localhost"===t||/^[\d.]+$/.test(t))return{tag:"local"};if(t.endsWith(".test.snokam.no"))return{tag:"test",domain:".test.snokam.no"};if(t.endsWith(".snokam.no"))return{tag:"prod",domain:".snokam.no"};const e=t.split(".");if(e.length>=2){const t=e.slice(-2).join(".");return{tag:t.replace(/\./g,"-"),domain:`.${t}`}}return{tag:"host"}})();return{name:`${r}next-auth.${i}.session-token`,domain:s,secure:o}}(process.env.NEXTAUTH_URL);return{secret:e.nextAuthSecret,pages:{signIn:"/auth/login"},providers:[s()({clientId:e.clientId,clientSecret:e.clientSecret,tenantId:e.tenantId,authorization:{params:c()}})],cookies:{sessionToken:{name:t,options:{path:"/",httpOnly:!0,sameSite:"lax",secure:o,domain:n}}},callbacks:{signIn(t){return u(this,arguments,void 0,(function*({account:t}){if("production"===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))},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:()=>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 s(e){try{a(i.next(e))}catch(e){r(e)}}function c(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(s,c)}a((i=i.apply(t,n||[])).next())}));var t,n,o,i};var s=n(333);const c=require("next-auth/jwt");var a=n(542);const u=require("next-auth/next"),l={Routes:s.default,Token:function(e){return t=this,n=void 0,i=function*(){const{req:t,res:n,authConfig:o}=e,i=(0,s.getNextAuthOptions)(o),u=yield(0,a.getServerSession)(t,n,i);if(!(null==u?void 0:u.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,s=yield(0,c.getToken)({req:t,secret:e,cookieName:i.cookies.sessionToken.name});if(!s)return n.status(500).end("Failed to get refetch token");const a=new r.ConfidentialClientApplication({auth:{clientId:o.clientId,clientSecret:o.clientSecret,authority:`https://login.microsoftonline.com/${o.tenantId}`}}),u=yield a.acquireTokenByRefreshToken({scopes:[t.body.scope],refreshToken:null==s?void 0:s.refreshToken});return u?n.status(200).json({accessToken:null==u?void 0:u.accessToken,expiresOn:Math.floor(u.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 s(e){try{a(i.next(e))}catch(e){r(e)}}function c(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(s,c)}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,kCCTTH,EAAOD,QAAUK,QAAQ,Y,UCAzBJ,EAAOD,QAAUK,QAAQ,mB,sFCAzB,MAAM,EAA+BA,QAAQ,gC,aCAtC,MAAMC,EAAuB,KAChC,MAAMC,EAA8B,oBAAXC,OACnBC,EAASF,GAAaC,OAAOE,SAASC,SAASC,SAAS,SACxDC,EAAS,CACXC,MAAO,6EAKX,OAHIP,IACAM,EAAOE,YAAcN,EAAS,iBAAmB,aAE9CI,CAAM,E,aCTbG,EAAwC,SAAUC,EAASC,EAAYC,EAAGC,GAE1E,OAAO,IAAKD,IAAMA,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,GACJ,EAMO,MAAMO,EAAsBC,IAC/B,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AU,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,CA0D9E,G","sources":["webpack://snokam/webpack/universalModuleDefinition","webpack://snokam/external commonjs \"next-auth\"","webpack://snokam/external commonjs \"@azure/msal-node\"","webpack://snokam/external commonjs \"next-auth/providers/azure-ad\"","webpack://snokam/./src/utils/params.ts","webpack://snokam/./src/options.tsx","webpack://snokam/./src/utils/cookies.ts","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\");","module.exports = require(\"@azure/msal-node\");","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\";\nimport { getSessionCookieSettings } from \"./utils/cookies\";\nexport const getNextAuthOptions = (config) => {\n const { name, domain, secure } = getSessionCookieSettings(process.env.NEXTAUTH_URL);\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 cookies: {\n sessionToken: {\n name,\n options: {\n path: \"/\",\n httpOnly: true,\n sameSite: \"lax\",\n secure,\n domain,\n },\n },\n },\n callbacks: {\n signIn(_a) {\n return __awaiter(this, arguments, void 0, function* ({ account }) {\n const isProd = process.env.NEXT_PUBLIC_VERCEL_ENV === \"production\";\n if (isProd) {\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","export function getSessionCookieSettings(nextAuthUrl) {\n const { hostname, protocol } = new URL(nextAuthUrl);\n const secure = protocol === \"https:\";\n const prefix = secure ? \"__Secure-\" : \"\";\n const getTagAndDomain = () => {\n if (hostname === \"localhost\" || /^[\\d.]+$/.test(hostname)) {\n return { tag: \"local\" };\n }\n if (hostname.endsWith(\".test.snokam.no\")) {\n return { tag: \"test\", domain: \".test.snokam.no\" };\n }\n if (hostname.endsWith(\".snokam.no\")) {\n return { tag: \"prod\", domain: \".snokam.no\" };\n }\n const parts = hostname.split(\".\");\n if (parts.length >= 2) {\n const base = parts.slice(-2).join(\".\");\n return { tag: base.replace(/\\./g, \"-\"), domain: `.${base}` };\n }\n return { tag: \"host\" };\n };\n const { tag, domain } = getTagAndDomain();\n const name = `${prefix}next-auth.${tag}.session-token`;\n return { name, domain, secure };\n}\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","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 options = getNextAuthOptions(authConfig);\n const session = yield getServerSession(req, res, options);\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({\n req,\n secret: nextAuthSecret,\n cookieName: options.cookies.sessionToken.name,\n });\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","name","domain","secure","nextAuthUrl","protocol","URL","prefix","tag","test","endsWith","parts","split","length","base","slice","join","replace","getTagAndDomain","getSessionCookieSettings","process","env","NEXTAUTH_URL","secret","nextAuthSecret","pages","signIn","providers","clientId","clientSecret","tenantId","authorization","cookies","sessionToken","options","path","httpOnly","sameSite","callbacks","_a","arguments","account","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","catch","console","error","Routes","Token","req","res","authConfig","session","getServerSession","user","end","body","refetchTokenResult","getToken","cookieName","accessTokenResult","json","expiresOn","Math","floor","getTime"],"sourceRoot":""}
1
+ {"version":3,"file":"server.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAgB,OAAID,IAEpBD,EAAa,OAAIC,GAClB,CATD,CASGK,MAAM,I,8GCTT,MAAM,EAA+BC,QAAQ,gC,aCAtC,MAAMC,EAAuB,KAChC,MAAMC,EAA8B,oBAAXC,OACnBC,EAASF,GAAaC,OAAOE,SAASC,SAASC,SAAS,SACxDC,EAAS,CACXC,MAAO,6EAKX,OAHIP,IACAM,EAAOE,YAAcN,EAAS,iBAAmB,aAE9CI,CAAM,E,aCTbG,EAAwC,SAAUC,EAASC,EAAYC,EAAGC,GAE1E,OAAO,IAAKD,IAAMA,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,GACJ,EAMO,MAAMO,EAAsBC,IAC/B,MAAM,KAAEC,EAAI,OAAEC,EAAM,OAAEC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AFgEzH,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,CA0D9E,G","sources":["webpack://snokam/webpack/universalModuleDefinition","webpack://snokam/external commonjs \"next-auth/providers/azure-ad\"","webpack://snokam/./src/utils/params.ts","webpack://snokam/./src/options.tsx","webpack://snokam/./src/utils/cookies.ts","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/./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\");","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\";\nimport { getSessionCookieSettings } from \"./utils/cookies\";\nexport const getNextAuthOptions = (config) => {\n const { name, domain, secure } = getSessionCookieSettings(process.env.NEXTAUTH_URL);\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 cookies: {\n sessionToken: {\n name,\n options: {\n path: \"/\",\n httpOnly: true,\n sameSite: \"lax\",\n secure,\n domain,\n },\n },\n },\n callbacks: {\n signIn(_a) {\n return __awaiter(this, arguments, void 0, function* ({ account }) {\n const isProd = process.env.NEXT_PUBLIC_VERCEL_ENV === \"production\";\n if (isProd) {\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","export function getSessionCookieSettings(nextAuthUrl) {\n const { hostname, protocol } = new URL(nextAuthUrl);\n const secure = protocol === \"https:\";\n const prefix = secure ? \"__Secure-\" : \"\";\n const getTagAndDomain = () => {\n if (hostname === \"localhost\" || /^[\\d.]+$/.test(hostname)) {\n return { tag: \"local\" };\n }\n if (hostname.endsWith(\".test.snokam.no\")) {\n return { tag: \"test\", domain: \".test.snokam.no\" };\n }\n if (hostname.endsWith(\".snokam.no\")) {\n return { tag: \"prod\", domain: \".snokam.no\" };\n }\n const parts = hostname.split(\".\");\n if (parts.length >= 2) {\n const base = parts.slice(-2).join(\".\");\n return { tag: base.replace(/\\./g, \"-\"), domain: `.${base}` };\n }\n return { tag: \"host\" };\n };\n const { tag, domain } = getTagAndDomain();\n const name = `${prefix}next-auth.${tag}.session-token`;\n return { name, domain, secure };\n}\n","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};","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 options = getNextAuthOptions(authConfig);\n const session = yield getServerSession(req, res, options);\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({\n req,\n secret: nextAuthSecret,\n cookieName: options.cookies.sessionToken.name,\n });\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","name","domain","secure","nextAuthUrl","protocol","URL","prefix","tag","test","endsWith","parts","split","length","base","slice","join","replace","getTagAndDomain","getSessionCookieSettings","process","env","NEXTAUTH_URL","secret","nextAuthSecret","pages","signIn","providers","clientId","clientSecret","tenantId","authorization","cookies","sessionToken","options","path","httpOnly","sameSite","callbacks","_a","arguments","account","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","catch","console","error","Routes","Token","req","res","authConfig","session","getServerSession","user","end","body","refetchTokenResult","getToken","cookieName","accessTokenResult","json","expiresOn","Math","floor","getTime"],"sourceRoot":""}
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.10",
4
+ "version": "2.2.12",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -24,13 +24,13 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@azure/msal-node": "^3.5.3",
27
+ "@azure/msal-node": "^3.7.3",
28
28
  "@emotion/react": "^11.14.0",
29
- "@emotion/styled": "^11.14.0",
30
- "@mui/material": "^7.1.0",
31
- "@snokam/core": "^1.4.3",
29
+ "@emotion/styled": "^11.14.1",
30
+ "@mui/material": "^7.3.2",
31
+ "@snokam/core": "^1.4.5",
32
32
  "next-auth": "^4.24.11",
33
- "path-to-regexp": "^8.2.0"
33
+ "path-to-regexp": "^8.3.0"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "next": "*",
@@ -67,5 +67,5 @@
67
67
  ]
68
68
  }
69
69
  },
70
- "gitHead": "b44fea65f2b90d679c8156de1c0902e35c72f81d"
70
+ "gitHead": "cafd7892ae2d87f417cc6be50b83884e42eb3d87"
71
71
  }