@authdog/nextjs-app 0.0.11 → 0.0.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/README.md +2 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/index.server.d.mts +1 -1
- package/dist/index.server.d.ts +1 -1
- package/dist/index.server.js +1 -1
- package/dist/index.server.js.map +1 -1
- package/dist/index.server.mjs +1 -1
- package/dist/index.server.mjs.map +1 -1
- package/package.json +3 -12
- package/dist/commons-CoLIU2e7.d.mts +0 -7
- package/dist/commons-CoLIU2e7.d.ts +0 -7
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";"use client";var f=Object.create;var s=Object.defineProperty;var
|
|
1
|
+
"use strict";"use client";var f=Object.create;var s=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var v=(t,e)=>{for(var r in e)s(t,r,{get:e[r],enumerable:!0})},g=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of p(e))!k.call(t,i)&&i!==r&&s(t,i,{get:()=>e[i],enumerable:!(n=h(e,i))||n.enumerable});return t};var x=(t,e,r)=>(r=t!=null?f(w(t)):{},g(e||!t||!t.__esModule?s(r,"default",{value:t,enumerable:!0}):r,t)),y=t=>g(s({},"__esModule",{value:!0}),t);var P={};v(P,{AuthdogProvider:()=>u,browserCookiesOptions:()=>m,fetchUserData:()=>c,getTokenFromUri:()=>d,validatePublicKey:()=>a});module.exports=y(P);var l=require("@authdog/node-commons"),d=t=>new URL(t).searchParams.get("token"),a=t=>{if(!t)throw new Error("Public key is not defined");if(!t.startsWith("pk_"))throw new Error("Invalid public key")},c=async(t,e)=>{a(t);let r=(0,l.getPublicKeyPayload)(t),n=await fetch(`${r==null?void 0:r.identityHost}/oidc/${r==null?void 0:r.environmentId}/userinfo`,{headers:{authorization:`Bearer ${e}`}});if(!n.ok)throw new Error("Failed to fetch user info");return await n.json()},m={maxAge:60*60*24*7,path:"/",httpOnly:!0};var o=x(require("react")),u=({children:t})=>((0,o.useEffect)(()=>{let e=new URLSearchParams(window.location.search).get("token");e&&(localStorage.setItem("token",e),window.history.replaceState({},document.title,"/"))},[]),o.default.createElement(o.default.Fragment,null,t));0&&(module.exports={AuthdogProvider,browserCookiesOptions,fetchUserData,getTokenFromUri,validatePublicKey});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/client/session.ts","../src/client/Provider.tsx"],"sourcesContent":["\"use client\";\nexport * from \"./client\";","import { getPublicKeyPayload } from \"@authdog/node-commons\";\n\nexport const getTokenFromUri = (url: string): string | null => {\n return new URL(url).searchParams.get(\"token\");\n};\n\ninterface IFetchUserData {\n user: {\n id: string;\n environmentId: string;\n externalId: string;\n userName: string;\n displayName: string;\n nickName: string;\n profileUrl: string;\n title: string;\n userType: string;\n preferredLanguage: string | null;\n locale: string | null;\n timezone: string | null;\n active: boolean;\n provider: string;\n lastLogin: string;\n createdAt: string;\n updatedAt: string;\n names: {\n id: string;\n userId: string;\n formatted: string | null;\n familyName: string;\n givenName: string;\n middleName: string | null;\n honorificPrefix: string | null;\n honorificSuffix: string | null;\n createdAt: string;\n updatedAt: string;\n };\n addresses: [];\n emails: {\n value: string;\n primary: boolean;\n type: string;\n }[];\n phoneNumbers: [];\n ims: [];\n photos: {\n value: string;\n type: string;\n }[];\n };\n meta: {\n code: number;\n message: string;\n };\n}\n\nexport const validatePublicKey = (publicKey: string) => {\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n\n if (!publicKey.startsWith(\"pk_\")) {\n throw new Error(\"Invalid public key\");\n }\n};\n\nexport const fetchUserData = async (\n publicKey: string,\n token: string,\n): Promise<IFetchUserData | null> => {\n validatePublicKey(publicKey);\n const publicKeyObj = getPublicKeyPayload(publicKey);\n const userData = await fetch(\n `${publicKeyObj?.identityHost}/oidc/${publicKeyObj?.environmentId}/userinfo`,\n {\n headers: {\n authorization: `Bearer ${token}`,\n },\n },\n );\n\n if (!userData.ok) {\n throw new Error(\"Failed to fetch user info\");\n }\n\n return await userData.json();\n};\n\nexport const browserCookiesOptions = {\n maxAge: 60 * 60 * 24 * 7, // 1 week\n path: \"/\",\n httpOnly: true,\n};\n","import React, { useEffect } from \"react\";\nexport const AuthdogProvider = ({\n children,\n}: {\n children: React.ReactNode;\n}) => {\n useEffect(() => {\n const token = new URLSearchParams(window.location.search).get(\"token\");\n if (token) {\n localStorage.setItem(\"token\", token);\n window.history.replaceState({}, document.title, \"/\");\n }\n }, []);\n return <>{children}</>;\n};\n"],"mappings":"ukBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,0BAAAC,EAAA,kBAAAC,EAAA,oBAAAC,EAAA,sBAAAC,IAAA,eAAAC,EAAAP,GCAA,IAAAQ,EAAoC,iCAEvBC,EAAmBC,GACvB,IAAI,IAAIA,CAAG,EAAE,aAAa,IAAI,OAAO,EAqDjCC,EAAqBC,GAAsB,CACtD,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,2BAA2B,EAG7C,GAAI,CAACA,EAAU,WAAW,KAAK,EAC7B,MAAM,IAAI,MAAM,oBAAoB,CAExC,EAEaC,EAAgB,MAC3BD,EACAE,IACmC,CACnCH,EAAkBC,CAAS,EAC3B,IAAMG,KAAe,uBAAoBH,CAAS,EAC5CI,EAAW,MAAM,MACrB,GAAGD,GAAA,YAAAA,EAAc,YAAY,SAASA,GAAA,YAAAA,EAAc,aAAa,YACjE,CACE,QAAS,CACP,cAAe,UAAUD,CAAK,EAChC,CACF,CACF,EAEA,GAAI,CAACE,EAAS,GACZ,MAAM,IAAI,MAAM,2BAA2B,EAG7C,OAAO,MAAMA,EAAS,KAAK,CAC7B,EAEaC,EAAwB,CACnC,OAAQ,GAAK,GAAK,GAAK,EACvB,KAAM,IACN,SAAU,EACZ,EC5FA,IAAAC,EAAiC,oBACpBC,EAAkB,CAAC,CAC9B,SAAAC,CACF,QAGE,aAAU,IAAM,CACd,IAAMC,EAAQ,IAAI,gBAAgB,OAAO,SAAS,MAAM,EAAE,IAAI,OAAO,EACjEA,IACF,aAAa,QAAQ,QAASA,CAAK,EACnC,OAAO,QAAQ,aAAa,CAAC,EAAG,SAAS,MAAO,GAAG,EAEvD,EAAG,CAAC,CAAC,EACE,EAAAC,QAAA,gBAAAA,QAAA,cAAGF,CAAS","names":["index_exports","__export","AuthdogProvider","browserCookiesOptions","fetchUserData","getTokenFromUri","validatePublicKey","__toCommonJS","import_node_commons","getTokenFromUri","url","validatePublicKey","publicKey","fetchUserData","token","publicKeyObj","userData","browserCookiesOptions","import_react","AuthdogProvider","children","token","React"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";
|
|
1
|
+
"use client";import{getPublicKeyPayload as s}from"@authdog/node-commons";var a=t=>new URL(t).searchParams.get("token"),i=t=>{if(!t)throw new Error("Public key is not defined");if(!t.startsWith("pk_"))throw new Error("Invalid public key")},g=async(t,r)=>{i(t);let e=s(t),n=await fetch(`${e==null?void 0:e.identityHost}/oidc/${e==null?void 0:e.environmentId}/userinfo`,{headers:{authorization:`Bearer ${r}`}});if(!n.ok)throw new Error("Failed to fetch user info");return await n.json()},l={maxAge:60*60*24*7,path:"/",httpOnly:!0};import o,{useEffect as d}from"react";var c=({children:t})=>(d(()=>{let r=new URLSearchParams(window.location.search).get("token");r&&(localStorage.setItem("token",r),window.history.replaceState({},document.title,"/"))},[]),o.createElement(o.Fragment,null,t));export{c as AuthdogProvider,l as browserCookiesOptions,g as fetchUserData,a as getTokenFromUri,i as validatePublicKey};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/client/session.ts","../src/client/Provider.tsx"],"sourcesContent":["import { getPublicKeyPayload } from \"@authdog/node-commons\";\n\nexport const getTokenFromUri = (url: string): string | null => {\n return new URL(url).searchParams.get(\"token\");\n};\n\ninterface IFetchUserData {\n user: {\n id: string;\n environmentId: string;\n externalId: string;\n userName: string;\n displayName: string;\n nickName: string;\n profileUrl: string;\n title: string;\n userType: string;\n preferredLanguage: string | null;\n locale: string | null;\n timezone: string | null;\n active: boolean;\n provider: string;\n lastLogin: string;\n createdAt: string;\n updatedAt: string;\n names: {\n id: string;\n userId: string;\n formatted: string | null;\n familyName: string;\n givenName: string;\n middleName: string | null;\n honorificPrefix: string | null;\n honorificSuffix: string | null;\n createdAt: string;\n updatedAt: string;\n };\n addresses: [];\n emails: {\n value: string;\n primary: boolean;\n type: string;\n }[];\n phoneNumbers: [];\n ims: [];\n photos: {\n value: string;\n type: string;\n }[];\n };\n meta: {\n code: number;\n message: string;\n };\n}\n\nexport const validatePublicKey = (publicKey: string) => {\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n\n if (!publicKey.startsWith(\"pk_\")) {\n throw new Error(\"Invalid public key\");\n }\n};\n\nexport const fetchUserData = async (\n publicKey: string,\n token: string,\n): Promise<IFetchUserData | null> => {\n validatePublicKey(publicKey);\n const publicKeyObj = getPublicKeyPayload(publicKey);\n const userData = await fetch(\n `${publicKeyObj?.identityHost}/oidc/${publicKeyObj?.environmentId}/userinfo`,\n {\n headers: {\n authorization: `Bearer ${token}`,\n },\n },\n );\n\n if (!userData.ok) {\n throw new Error(\"Failed to fetch user info\");\n }\n\n return await userData.json();\n};\n\nexport const browserCookiesOptions = {\n maxAge: 60 * 60 * 24 * 7, // 1 week\n path: \"/\",\n httpOnly: true,\n};\n","import React, { useEffect } from \"react\";\nexport const AuthdogProvider = ({\n children,\n}: {\n children: React.ReactNode;\n}) => {\n useEffect(() => {\n const token = new URLSearchParams(window.location.search).get(\"token\");\n if (token) {\n localStorage.setItem(\"token\", token);\n window.history.replaceState({}, document.title, \"/\");\n }\n }, []);\n return <>{children}</>;\n};\n"],"mappings":"aAAA,OAAS,uBAAAA,MAA2B,wBAE7B,IAAMC,EAAmBC,GACvB,IAAI,IAAIA,CAAG,EAAE,aAAa,IAAI,OAAO,EAqDjCC,EAAqBC,GAAsB,CACtD,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,2BAA2B,EAG7C,GAAI,CAACA,EAAU,WAAW,KAAK,EAC7B,MAAM,IAAI,MAAM,oBAAoB,CAExC,EAEaC,EAAgB,MAC3BD,EACAE,IACmC,CACnCH,EAAkBC,CAAS,EAC3B,IAAMG,EAAeP,EAAoBI,CAAS,EAC5CI,EAAW,MAAM,MACrB,GAAGD,GAAA,YAAAA,EAAc,YAAY,SAASA,GAAA,YAAAA,EAAc,aAAa,YACjE,CACE,QAAS,CACP,cAAe,UAAUD,CAAK,EAChC,CACF,CACF,EAEA,GAAI,CAACE,EAAS,GACZ,MAAM,IAAI,MAAM,2BAA2B,EAG7C,OAAO,MAAMA,EAAS,KAAK,CAC7B,EAEaC,EAAwB,CACnC,OAAQ,GAAK,GAAK,GAAK,EACvB,KAAM,IACN,SAAU,EACZ,EC5FA,OAAOC,GAAS,aAAAC,MAAiB,QAC1B,IAAMC,EAAkB,CAAC,CAC9B,SAAAC,CACF,KAGEF,EAAU,IAAM,CACd,IAAMG,EAAQ,IAAI,gBAAgB,OAAO,SAAS,MAAM,EAAE,IAAI,OAAO,EACjEA,IACF,aAAa,QAAQ,QAASA,CAAK,EACnC,OAAO,QAAQ,aAAa,CAAC,EAAG,SAAS,MAAO,GAAG,EAEvD,EAAG,CAAC,CAAC,EACEJ,EAAA,cAAAA,EAAA,cAAGG,CAAS","names":["getPublicKeyPayload","getTokenFromUri","url","validatePublicKey","publicKey","fetchUserData","token","publicKeyObj","userData","browserCookiesOptions","React","useEffect","AuthdogProvider","children","token"]}
|
package/dist/index.server.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PublicKeyPayload } from '@authdog/node-commons';
|
|
2
2
|
import { NextRequest, NextResponse } from 'next/server';
|
|
3
3
|
import * as next_dist_compiled__edge_runtime_cookies from 'next/dist/compiled/@edge-runtime/cookies';
|
|
4
4
|
|
package/dist/index.server.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PublicKeyPayload } from '@authdog/node-commons';
|
|
2
2
|
import { NextRequest, NextResponse } from 'next/server';
|
|
3
3
|
import * as next_dist_compiled__edge_runtime_cookies from 'next/dist/compiled/@edge-runtime/cookies';
|
|
4
4
|
|
package/dist/index.server.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";"use server";var
|
|
1
|
+
"use strict";"use server";var k=Object.create;var u=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var A=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),v=(e,t)=>{for(var r in t)u(e,r,{get:t[r],enumerable:!0})},p=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of q(t))!N.call(e,s)&&s!==r&&u(e,s,{get:()=>t[s],enumerable:!(i=w(t,s))||i.enumerable});return e};var I=(e,t,r)=>(r=e!=null?k(S(e)):{},p(t||!e||!e.__esModule?u(r,"default",{value:e,enumerable:!0}):r,e)),b=e=>p(u({},"__esModule",{value:!0}),e);var x=A((n,d)=>{"use strict";var o={NextRequest:require("next/dist/server/web/spec-extension/request").NextRequest,NextResponse:require("next/dist/server/web/spec-extension/response").NextResponse,ImageResponse:require("next/dist/server/web/spec-extension/image-response").ImageResponse,userAgentFromString:require("next/dist/server/web/spec-extension/user-agent").userAgentFromString,userAgent:require("next/dist/server/web/spec-extension/user-agent").userAgent,URLPattern:require("next/dist/server/web/spec-extension/url-pattern").URLPattern,after:require("next/dist/server/after").after,connection:require("next/dist/server/request/connection").connection};d.exports=o;n.NextRequest=o.NextRequest;n.NextResponse=o.NextResponse;n.ImageResponse=o.ImageResponse;n.userAgentFromString=o.userAgentFromString;n.userAgent=o.userAgent;n.URLPattern=o.URLPattern;n.after=o.after;n.connection=o.connection});var E={};v(E,{getServerSidePayloadPublicKey:()=>_,getSessionCookie:()=>y,useAuthMiddleware:()=>R});module.exports=b(E);var h=require("@authdog/node-commons");var l=I(x()),R=e=>{if(!e)throw new Error("Public key is not defined");if(!e.startsWith("pk_"))throw new Error("Invalid public key");let t=JSON.parse(Buffer.from(e.replace("pk_",""),"base64").toString("utf-8"));return async r=>{var m;let i=l.NextResponse.next(),s={maxAge:60*60*24*7,path:"/",httpOnly:!0},f=new URL(r.nextUrl).searchParams.get("token");if(f){let g=await fetch(`${t.identityHost}/oidc/${t.environmentId}/userinfo`,{headers:{authorization:`Bearer ${f}`}});if(!g.ok)throw new Error("Failed to fetch user info");let a=await g.json();((m=a==null?void 0:a.meta)==null?void 0:m.code)===200&&(i.cookies.set({name:`user_session_${t.environmentId}`,value:JSON.stringify(a.user),...s}),i.cookies.set({name:`user_session_hash_${t.environmentId}`,value:f,...s}))}return i}};var P=require("next/headers"),c=require("@authdog/node-commons"),y=async e=>{if(!e)throw new Error("Public key is not defined");let t=(0,c.getPublicKeyPayload)(e);return(await(0,P.cookies)()).get((0,c.buildSessionKey)(t==null?void 0:t.environmentId))};var _=e=>{if(!e)throw new Error("Public key is not defined");return(0,h.getPublicKeyPayload)(e)};0&&(module.exports={getServerSidePayloadPublicKey,getSessionCookie,useAuthMiddleware});
|
|
2
2
|
//# sourceMappingURL=index.server.js.map
|
package/dist/index.server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../node_modules/.pnpm/next@15.1.0_@opentelemetry+api@1.8.0_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/next/server.js","../src/index.server.ts","../src/
|
|
1
|
+
{"version":3,"sources":["../../../node_modules/.pnpm/next@15.1.0_@opentelemetry+api@1.8.0_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/next/server.js","../src/index.server.ts","../src/server/index.ts","../src/server/middleware.ts","../src/server/cookies.ts"],"sourcesContent":["const serverExports = {\n NextRequest: require('next/dist/server/web/spec-extension/request')\n .NextRequest,\n NextResponse: require('next/dist/server/web/spec-extension/response')\n .NextResponse,\n ImageResponse: require('next/dist/server/web/spec-extension/image-response')\n .ImageResponse,\n userAgentFromString: require('next/dist/server/web/spec-extension/user-agent')\n .userAgentFromString,\n userAgent: require('next/dist/server/web/spec-extension/user-agent')\n .userAgent,\n URLPattern: require('next/dist/server/web/spec-extension/url-pattern')\n .URLPattern,\n after: require('next/dist/server/after').after,\n connection: require('next/dist/server/request/connection').connection,\n}\n\n// https://nodejs.org/api/esm.html#commonjs-namespaces\n// When importing CommonJS modules, the module.exports object is provided as the default export\nmodule.exports = serverExports\n\n// make import { xxx } from 'next/server' work\nexports.NextRequest = serverExports.NextRequest\nexports.NextResponse = serverExports.NextResponse\nexports.ImageResponse = serverExports.ImageResponse\nexports.userAgentFromString = serverExports.userAgentFromString\nexports.userAgent = serverExports.userAgent\nexports.URLPattern = serverExports.URLPattern\nexports.after = serverExports.after\nexports.connection = serverExports.connection\n","\"use server\";\nexport * from \"./server\";\n","import { getPublicKeyPayload, PublicKeyPayload } from \"@authdog/node-commons\";\n\nexport { useAuthMiddleware } from \"./middleware\";\nexport { getSessionCookie } from \"./cookies\";\n\nexport const getServerSidePayloadPublicKey = (publicKey: string): PublicKeyPayload => {\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n return getPublicKeyPayload(publicKey);\n};","import { NextResponse, type NextRequest } from \"next/server\";\n\nexport const useAuthMiddleware = (publicKey: string) => {\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n\n if (!publicKey.startsWith(\"pk_\")) {\n throw new Error(\"Invalid public key\");\n }\n\n const publicKeyObj = JSON.parse(\n Buffer.from(publicKey.replace(\"pk_\", \"\"), \"base64\").toString(\"utf-8\"),\n );\n\n return async (request: NextRequest) => {\n const response = NextResponse.next();\n const options = {\n maxAge: 60 * 60 * 24 * 7, // 1 week\n path: \"/\",\n httpOnly: true,\n };\n\n const tokenFromUri = new URL(request.nextUrl).searchParams.get(\"token\");\n\n if (tokenFromUri) {\n const userData = await fetch(\n `${publicKeyObj.identityHost}/oidc/${publicKeyObj.environmentId}/userinfo`,\n {\n headers: {\n authorization: `Bearer ${tokenFromUri}`,\n },\n },\n );\n\n if (!userData.ok) {\n throw new Error(\"Failed to fetch user info\");\n }\n\n const authenticatedUser = await userData.json();\n\n if (authenticatedUser?.meta?.code === 200) {\n // TODO: define object in node-commons\n response.cookies.set({\n name: `user_session_${publicKeyObj.environmentId}`,\n value: JSON.stringify(authenticatedUser.user),\n ...options,\n });\n\n response.cookies.set({\n name: `user_session_hash_${publicKeyObj.environmentId}`,\n value: tokenFromUri,\n ...options,\n });\n }\n }\n // TODO: token from cookies\n\n return response;\n };\n};\n","import { cookies } from \"next/headers\";\nimport {buildSessionKey, getPublicKeyPayload} from \"@authdog/node-commons\";\n\nexport const getSessionCookie = async (publicKey: string) => {\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n const publicKeyObj = getPublicKeyPayload(publicKey);\n const cookieStore = await cookies();\n return cookieStore.get(buildSessionKey(publicKeyObj?.environmentId));\n};\n"],"mappings":"ioBAAA,IAAAA,EAAAC,EAAA,CAAAC,EAAAC,IAAA,kBAAMC,EAAgB,CACpB,YAAa,QAAQ,6CAA6C,EAC/D,YACH,aAAc,QAAQ,8CAA8C,EACjE,aACH,cAAe,QAAQ,oDAAoD,EACxE,cACH,oBAAqB,QAAQ,g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B,MAAMD,EAAS,KAAK,IAE1CJ,EAAAK,GAAA,YAAAA,EAAmB,OAAnB,YAAAL,EAAyB,QAAS,MAEpCC,EAAS,QAAQ,IAAI,CACnB,KAAM,gBAAgBH,EAAa,aAAa,GAChD,MAAO,KAAK,UAAUO,EAAkB,IAAI,EAC5C,GAAGH,CACL,CAAC,EAEDD,EAAS,QAAQ,IAAI,CACnB,KAAM,qBAAqBH,EAAa,aAAa,GACrD,MAAOK,EACP,GAAGD,CACL,CAAC,EAEL,CAGA,OAAOD,CACT,CACF,EC5DA,IAAAK,EAAwB,wBACxBC,EAAmD,iCAEtCC,EAAmB,MAAOC,GAAsB,CAC3D,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,2BAA2B,EAE7C,IAAMC,KAAe,uBAAoBD,CAAS,EAElD,OADoB,QAAM,WAAQ,GACf,OAAI,mBAAgBC,GAAA,YAAAA,EAAc,aAAa,CAAC,CACrE,EFLO,IAAMC,EAAiCC,GAAwC,CAC9E,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,2BAA2B,EAE7C,SAAO,uBAAoBA,CAAS,CAC5C","names":["require_server","__commonJSMin","exports","module","serverExports","index_server_exports","__export","getServerSidePayloadPublicKey","getSessionCookie","useAuthMiddleware","__toCommonJS","import_node_commons","import_server","useAuthMiddleware","publicKey","publicKeyObj","request","_a","response","options","tokenFromUri","userData","authenticatedUser","import_headers","import_node_commons","getSessionCookie","publicKey","publicKeyObj","getServerSidePayloadPublicKey","publicKey"]}
|
package/dist/index.server.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use server";var
|
|
1
|
+
"use server";var l=Object.create;var g=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty;var i=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var k=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var w=(e,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of P(t))!h.call(e,s)&&s!==r&&g(e,s,{get:()=>t[s],enumerable:!(a=R(t,s))||a.enumerable});return e};var q=(e,t,r)=>(r=e!=null?l(y(e)):{},w(t||!e||!e.__esModule?g(r,"default",{value:e,enumerable:!0}):r,e));var d=k((n,p)=>{"use strict";var o={NextRequest:i("next/dist/server/web/spec-extension/request").NextRequest,NextResponse:i("next/dist/server/web/spec-extension/response").NextResponse,ImageResponse:i("next/dist/server/web/spec-extension/image-response").ImageResponse,userAgentFromString:i("next/dist/server/web/spec-extension/user-agent").userAgentFromString,userAgent:i("next/dist/server/web/spec-extension/user-agent").userAgent,URLPattern:i("next/dist/server/web/spec-extension/url-pattern").URLPattern,after:i("next/dist/server/after").after,connection:i("next/dist/server/request/connection").connection};p.exports=o;n.NextRequest=o.NextRequest;n.NextResponse=o.NextResponse;n.ImageResponse=o.ImageResponse;n.userAgentFromString=o.userAgentFromString;n.userAgent=o.userAgent;n.URLPattern=o.URLPattern;n.after=o.after;n.connection=o.connection});import{getPublicKeyPayload as b}from"@authdog/node-commons";var x=q(d()),S=e=>{if(!e)throw new Error("Public key is not defined");if(!e.startsWith("pk_"))throw new Error("Invalid public key");let t=JSON.parse(Buffer.from(e.replace("pk_",""),"base64").toString("utf-8"));return async r=>{var f;let a=x.NextResponse.next(),s={maxAge:60*60*24*7,path:"/",httpOnly:!0},c=new URL(r.nextUrl).searchParams.get("token");if(c){let m=await fetch(`${t.identityHost}/oidc/${t.environmentId}/userinfo`,{headers:{authorization:`Bearer ${c}`}});if(!m.ok)throw new Error("Failed to fetch user info");let u=await m.json();((f=u==null?void 0:u.meta)==null?void 0:f.code)===200&&(a.cookies.set({name:`user_session_${t.environmentId}`,value:JSON.stringify(u.user),...s}),a.cookies.set({name:`user_session_hash_${t.environmentId}`,value:c,...s}))}return a}};import{cookies as N}from"next/headers";import{buildSessionKey as A,getPublicKeyPayload as v}from"@authdog/node-commons";var I=async e=>{if(!e)throw new Error("Public key is not defined");let t=v(e);return(await N()).get(A(t==null?void 0:t.environmentId))};var B=e=>{if(!e)throw new Error("Public key is not defined");return b(e)};export{B as getServerSidePayloadPublicKey,I as getSessionCookie,S as useAuthMiddleware};
|
|
2
2
|
//# sourceMappingURL=index.server.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../node_modules/.pnpm/next@15.1.0_@opentelemetry+api@1.8.0_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/next/server.js","../src/
|
|
1
|
+
{"version":3,"sources":["../../../node_modules/.pnpm/next@15.1.0_@opentelemetry+api@1.8.0_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/next/server.js","../src/server/index.ts","../src/server/middleware.ts","../src/server/cookies.ts"],"sourcesContent":["const serverExports = {\n NextRequest: require('next/dist/server/web/spec-extension/request')\n .NextRequest,\n NextResponse: require('next/dist/server/web/spec-extension/response')\n .NextResponse,\n ImageResponse: require('next/dist/server/web/spec-extension/image-response')\n .ImageResponse,\n userAgentFromString: require('next/dist/server/web/spec-extension/user-agent')\n .userAgentFromString,\n userAgent: require('next/dist/server/web/spec-extension/user-agent')\n .userAgent,\n URLPattern: require('next/dist/server/web/spec-extension/url-pattern')\n .URLPattern,\n after: require('next/dist/server/after').after,\n connection: require('next/dist/server/request/connection').connection,\n}\n\n// https://nodejs.org/api/esm.html#commonjs-namespaces\n// When importing CommonJS modules, the module.exports object is provided as the default export\nmodule.exports = serverExports\n\n// make import { xxx } from 'next/server' work\nexports.NextRequest = serverExports.NextRequest\nexports.NextResponse = serverExports.NextResponse\nexports.ImageResponse = serverExports.ImageResponse\nexports.userAgentFromString = serverExports.userAgentFromString\nexports.userAgent = serverExports.userAgent\nexports.URLPattern = serverExports.URLPattern\nexports.after = serverExports.after\nexports.connection = serverExports.connection\n","import { getPublicKeyPayload, PublicKeyPayload } from \"@authdog/node-commons\";\n\nexport { useAuthMiddleware } from \"./middleware\";\nexport { getSessionCookie } from \"./cookies\";\n\nexport const getServerSidePayloadPublicKey = (publicKey: string): PublicKeyPayload => {\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n return getPublicKeyPayload(publicKey);\n};","import { NextResponse, type NextRequest } from \"next/server\";\n\nexport const useAuthMiddleware = (publicKey: string) => {\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n\n if (!publicKey.startsWith(\"pk_\")) {\n throw new Error(\"Invalid public key\");\n }\n\n const publicKeyObj = JSON.parse(\n Buffer.from(publicKey.replace(\"pk_\", \"\"), \"base64\").toString(\"utf-8\"),\n );\n\n return async (request: NextRequest) => {\n const response = NextResponse.next();\n const options = {\n maxAge: 60 * 60 * 24 * 7, // 1 week\n path: \"/\",\n httpOnly: true,\n };\n\n const tokenFromUri = new URL(request.nextUrl).searchParams.get(\"token\");\n\n if (tokenFromUri) {\n const userData = await fetch(\n `${publicKeyObj.identityHost}/oidc/${publicKeyObj.environmentId}/userinfo`,\n {\n headers: {\n authorization: `Bearer ${tokenFromUri}`,\n },\n },\n );\n\n if (!userData.ok) {\n throw new Error(\"Failed to fetch user info\");\n }\n\n const authenticatedUser = await userData.json();\n\n if (authenticatedUser?.meta?.code === 200) {\n // TODO: define object in node-commons\n response.cookies.set({\n name: `user_session_${publicKeyObj.environmentId}`,\n value: JSON.stringify(authenticatedUser.user),\n ...options,\n });\n\n response.cookies.set({\n name: `user_session_hash_${publicKeyObj.environmentId}`,\n value: tokenFromUri,\n ...options,\n });\n }\n }\n // TODO: token from cookies\n\n return response;\n };\n};\n","import { cookies } from \"next/headers\";\nimport {buildSessionKey, getPublicKeyPayload} from \"@authdog/node-commons\";\n\nexport const getSessionCookie = async (publicKey: string) => {\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n const publicKeyObj = getPublicKeyPayload(publicKey);\n const cookieStore = await cookies();\n return cookie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AAa,aAAa,YAC/D,CACE,QAAS,CACP,cAAe,UAAUK,CAAY,EACvC,CACF,CACF,EAEA,GAAI,CAACC,EAAS,GACZ,MAAM,IAAI,MAAM,2BAA2B,EAG7C,IAAMC,EAAoB,MAAMD,EAAS,KAAK,IAE1CJ,EAAAK,GAAA,YAAAA,EAAmB,OAAnB,YAAAL,EAAyB,QAAS,MAEpCC,EAAS,QAAQ,IAAI,CACnB,KAAM,gBAAgBH,EAAa,aAAa,GAChD,MAAO,KAAK,UAAUO,EAAkB,IAAI,EAC5C,GAAGH,CACL,CAAC,EAEDD,EAAS,QAAQ,IAAI,CACnB,KAAM,qBAAqBH,EAAa,aAAa,GACrD,MAAOK,EACP,GAAGD,CACL,CAAC,EAEL,CAGA,OAAOD,CACT,CACF,EC5DA,OAAS,WAAAK,MAAe,eACxB,OAAQ,mBAAAC,EAAiB,uBAAAC,MAA0B,wBAE5C,IAAMC,EAAmB,MAAOC,GAAsB,CAC3D,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,2BAA2B,EAE7C,IAAMC,EAAeH,EAAoBE,CAAS,EAElD,OADoB,MAAMJ,EAAQ,GACf,IAAIC,EAAgBI,GAAA,YAAAA,EAAc,aAAa,CAAC,CACrE,EFLO,IAAMC,EAAiCC,GAAwC,CAC9E,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,2BAA2B,EAE7C,OAAOC,EAAoBD,CAAS,CAC5C","names":["require_server","__commonJSMin","exports","module","serverExports","getPublicKeyPayload","import_server","useAuthMiddleware","publicKey","publicKeyObj","request","_a","response","options","tokenFromUri","userData","authenticatedUser","cookies","buildSessionKey","getPublicKeyPayload","getSessionCookie","publicKey","publicKeyObj","getServerSidePayloadPublicKey","publicKey","getPublicKeyPayload"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authdog/nextjs-app",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "Authdog Next.js SDK",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,17 +11,8 @@
|
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"next": "^15.1.0",
|
|
14
|
-
"react": "^19.1.0"
|
|
15
|
-
|
|
16
|
-
"devDependencies": {
|
|
17
|
-
"@types/next": "^9.0.0",
|
|
18
|
-
"@types/node": "^22.10.5",
|
|
19
|
-
"@types/react": "^19.1.0",
|
|
20
|
-
"dotenv": "^16.4.7",
|
|
21
|
-
"prettier": "^3.4.2",
|
|
22
|
-
"tsup": "^8.3.5",
|
|
23
|
-
"typescript": "^5.7.2",
|
|
24
|
-
"vitest": "^2.1.8"
|
|
14
|
+
"react": "^19.1.0",
|
|
15
|
+
"@authdog/node-commons": "0.0.17"
|
|
25
16
|
},
|
|
26
17
|
"publishConfig": {
|
|
27
18
|
"registry": "https://registry.npmjs.org/",
|