@authdog/nextjs-app 0.0.12 → 0.0.14
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/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.server.js +1 -1
- package/dist/index.server.js.map +1 -1
- package/package.json +11 -5
- package/dist/index.d.mts +0 -65
- package/dist/index.mjs +0 -2
- package/dist/index.mjs.map +0 -1
- package/dist/index.server.d.mts +0 -11
- package/dist/index.server.mjs +0 -2
- package/dist/index.server.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use
|
|
1
|
+
"use client";import{getPublicKeyPayload as s}from"@authdog/node-commons";var a=e=>new URL(e).searchParams.get("token"),i=e=>{if(!e)throw new Error("Public key is not defined");if(!e.startsWith("pk_"))throw new Error("Invalid public key")},g=async(e,t)=>{i(e);let r=s(e),n=await fetch(`${r?.identityHost}/oidc/${r?.environmentId}/userinfo`,{headers:{authorization:`Bearer ${t}`}});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 c}from"react";var d=({children:e})=>(c(()=>{let t=new URLSearchParams(window.location.search).get("token");t&&(localStorage.setItem("token",t),window.history.replaceState({},document.title,"/"))},[]),o.createElement(o.Fragment,null,e));export{d as AuthdogProvider,l as browserCookiesOptions,g as fetchUserData,a as getTokenFromUri,i as validatePublicKey};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.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,GAAc,YAAY,SAASA,GAAc,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.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use
|
|
1
|
+
"use server";import{getPublicKeyPayload as p}from"@authdog/node-commons";import{NextResponse as c}from"next/server";var u=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 n=>{let o=c.next(),i={maxAge:60*60*24*7,path:"/",httpOnly:!0},r=new URL(n.nextUrl).searchParams.get("token");if(r){let s=await fetch(`${t.identityHost}/oidc/${t.environmentId}/userinfo`,{headers:{authorization:`Bearer ${r}`}});if(!s.ok)throw new Error("Failed to fetch user info");let a=await s.json();a?.meta?.code===200&&(o.cookies.set({name:`user_session_${t.environmentId}`,value:JSON.stringify(a.user),...i}),o.cookies.set({name:`user_session_hash_${t.environmentId}`,value:r,...i}))}return o}};import{cookies as d}from"next/headers";import{buildSessionKey as f,getPublicKeyPayload as l}from"@authdog/node-commons";var m=async e=>{if(!e)throw new Error("Public key is not defined");let t=l(e);return(await d()).get(f(t?.environmentId))};var b=e=>{if(!e)throw new Error("Public key is not defined");return p(e)};export{b as getServerSidePayloadPublicKey,m as getSessionCookie,u as useAuthMiddleware};
|
|
2
2
|
//# sourceMappingURL=index.server.js.map
|
package/dist/index.server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["
|
|
1
|
+
{"version":3,"sources":["../src/server/index.ts","../src/server/middleware.ts","../src/server/cookies.ts"],"sourcesContent":["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":"aAAA,OAAS,uBAAAA,MAA6C,wBCAtD,OAAS,gBAAAC,MAAsC,cAExC,IAAMC,EAAqBC,GAAsB,CACtD,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,2BAA2B,EAG7C,GAAI,CAACA,EAAU,WAAW,KAAK,EAC7B,MAAM,IAAI,MAAM,oBAAoB,EAGtC,IAAMC,EAAe,KAAK,MACxB,OAAO,KAAKD,EAAU,QAAQ,MAAO,EAAE,EAAG,QAAQ,EAAE,SAAS,OAAO,CACtE,EAEA,MAAO,OAAOE,GAAyB,CACrC,IAAMC,EAAWL,EAAa,KAAK,EAC7BM,EAAU,CACd,OAAQ,GAAK,GAAK,GAAK,EACvB,KAAM,IACN,SAAU,EACZ,EAEMC,EAAe,IAAI,IAAIH,EAAQ,OAAO,EAAE,aAAa,IAAI,OAAO,EAEtE,GAAIG,EAAc,CAChB,IAAMC,EAAW,MAAM,MACrB,GAAGL,EAAa,YAAY,SAASA,EAAa,aAAa,YAC/D,CACE,QAAS,CACP,cAAe,UAAUI,CAAY,EACvC,CACF,CACF,EAEA,GAAI,CAACC,EAAS,GACZ,MAAM,IAAI,MAAM,2BAA2B,EAG7C,IAAMC,EAAoB,MAAMD,EAAS,KAAK,EAE1CC,GAAmB,MAAM,OAAS,MAEpCJ,EAAS,QAAQ,IAAI,CACnB,KAAM,gBAAgBF,EAAa,aAAa,GAChD,MAAO,KAAK,UAAUM,EAAkB,IAAI,EAC5C,GAAGH,CACL,CAAC,EAEDD,EAAS,QAAQ,IAAI,CACnB,KAAM,qBAAqBF,EAAa,aAAa,GACrD,MAAOI,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,GAAc,aAAa,CAAC,CACrE,EFLO,IAAMC,EAAiCC,GAAwC,CAC9E,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,2BAA2B,EAE7C,OAAOC,EAAoBD,CAAS,CAC5C","names":["getPublicKeyPayload","NextResponse","useAuthMiddleware","publicKey","publicKeyObj","request","response","options","tokenFromUri","userData","authenticatedUser","cookies","buildSessionKey","getPublicKeyPayload","getSessionCookie","publicKey","publicKeyObj","getServerSidePayloadPublicKey","publicKey","getPublicKeyPayload"]}
|
package/package.json
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authdog/nextjs-app",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "Authdog Next.js SDK",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"source": "src/index.ts",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
9
15
|
"files": [
|
|
10
16
|
"dist/"
|
|
11
17
|
],
|
|
12
18
|
"dependencies": {
|
|
13
19
|
"next": "^15.1.0",
|
|
14
20
|
"react": "^19.1.0",
|
|
15
|
-
"@authdog/node-commons": "0.0.
|
|
21
|
+
"@authdog/node-commons": "0.0.19"
|
|
16
22
|
},
|
|
17
23
|
"publishConfig": {
|
|
18
24
|
"registry": "https://registry.npmjs.org/",
|
package/dist/index.d.mts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
|
|
3
|
-
declare const getTokenFromUri: (url: string) => string | null;
|
|
4
|
-
interface IFetchUserData {
|
|
5
|
-
user: {
|
|
6
|
-
id: string;
|
|
7
|
-
environmentId: string;
|
|
8
|
-
externalId: string;
|
|
9
|
-
userName: string;
|
|
10
|
-
displayName: string;
|
|
11
|
-
nickName: string;
|
|
12
|
-
profileUrl: string;
|
|
13
|
-
title: string;
|
|
14
|
-
userType: string;
|
|
15
|
-
preferredLanguage: string | null;
|
|
16
|
-
locale: string | null;
|
|
17
|
-
timezone: string | null;
|
|
18
|
-
active: boolean;
|
|
19
|
-
provider: string;
|
|
20
|
-
lastLogin: string;
|
|
21
|
-
createdAt: string;
|
|
22
|
-
updatedAt: string;
|
|
23
|
-
names: {
|
|
24
|
-
id: string;
|
|
25
|
-
userId: string;
|
|
26
|
-
formatted: string | null;
|
|
27
|
-
familyName: string;
|
|
28
|
-
givenName: string;
|
|
29
|
-
middleName: string | null;
|
|
30
|
-
honorificPrefix: string | null;
|
|
31
|
-
honorificSuffix: string | null;
|
|
32
|
-
createdAt: string;
|
|
33
|
-
updatedAt: string;
|
|
34
|
-
};
|
|
35
|
-
addresses: [];
|
|
36
|
-
emails: {
|
|
37
|
-
value: string;
|
|
38
|
-
primary: boolean;
|
|
39
|
-
type: string;
|
|
40
|
-
}[];
|
|
41
|
-
phoneNumbers: [];
|
|
42
|
-
ims: [];
|
|
43
|
-
photos: {
|
|
44
|
-
value: string;
|
|
45
|
-
type: string;
|
|
46
|
-
}[];
|
|
47
|
-
};
|
|
48
|
-
meta: {
|
|
49
|
-
code: number;
|
|
50
|
-
message: string;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
declare const validatePublicKey: (publicKey: string) => void;
|
|
54
|
-
declare const fetchUserData: (publicKey: string, token: string) => Promise<IFetchUserData | null>;
|
|
55
|
-
declare const browserCookiesOptions: {
|
|
56
|
-
maxAge: number;
|
|
57
|
-
path: string;
|
|
58
|
-
httpOnly: boolean;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
declare const AuthdogProvider: ({ children, }: {
|
|
62
|
-
children: React.ReactNode;
|
|
63
|
-
}) => React.JSX.Element;
|
|
64
|
-
|
|
65
|
-
export { AuthdogProvider, browserCookiesOptions, fetchUserData, getTokenFromUri, validatePublicKey };
|
package/dist/index.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { PublicKeyPayload } from '@authdog/node-commons';
|
|
2
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
-
import * as next_dist_compiled__edge_runtime_cookies from 'next/dist/compiled/@edge-runtime/cookies';
|
|
4
|
-
|
|
5
|
-
declare const useAuthMiddleware: (publicKey: string) => (request: NextRequest) => Promise<NextResponse<unknown>>;
|
|
6
|
-
|
|
7
|
-
declare const getSessionCookie: (publicKey: string) => Promise<next_dist_compiled__edge_runtime_cookies.RequestCookie | undefined>;
|
|
8
|
-
|
|
9
|
-
declare const getServerSidePayloadPublicKey: (publicKey: string) => PublicKeyPayload;
|
|
10
|
-
|
|
11
|
-
export { getServerSidePayloadPublicKey, getSessionCookie, useAuthMiddleware };
|
package/dist/index.server.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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
|
-
//# sourceMappingURL=index.server.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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 cookieStore.get(buildSessionKey(publicKeyObj?.environmentId));\n};\n"],"mappings":"+wBAAA,IAAAA,EAAAC,EAAA,CAAAC,EAAAC,IAAA,kBAAMC,EAAgB,CACpB,YAAa,EAAQ,6CAA6C,EAC/D,YACH,aAAc,EAAQ,8CAA8C,EACjE,aACH,cAAe,EAAQ,oDAAoD,EACxE,cACH,oBAAqB,EAAQ,gDAAgD,EAC1E,oBACH,UAAW,EAAQ,gDAAgD,EAChE,UACH,WAAY,EAAQ,iDAAiD,EAClE,WACH,MAAO,EAAQ,wBAAwB,EAAE,MACzC,WAAY,EAAQ,qCAAqC,EAAE,UAC7D,EAIAD,EAAO,QAAUC,EAGjBF,EAAQ,YAAcE,EAAc,YACpCF,EAAQ,aAAeE,EAAc,aACrCF,EAAQ,cAAgBE,EAAc,cACtCF,EAAQ,oBAAsBE,EAAc,oBAC5CF,EAAQ,UAAYE,EAAc,UAClCF,EAAQ,WAAaE,EAAc,WACnCF,EAAQ,MAAQE,EAAc,MAC9BF,EAAQ,WAAaE,EAAc,aC7BnC,OAAS,uBAAAC,MAA6C,wBCAtD,IAAAC,EAA+C,OAElCC,EAAqBC,GAAsB,CACtD,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,2BAA2B,EAG7C,GAAI,CAACA,EAAU,WAAW,KAAK,EAC7B,MAAM,IAAI,MAAM,oBAAoB,EAGtC,IAAMC,EAAe,KAAK,MACxB,OAAO,KAAKD,EAAU,QAAQ,MAAO,EAAE,EAAG,QAAQ,EAAE,SAAS,OAAO,CACtE,EAEA,MAAO,OAAOE,GAAyB,CAfzC,IAAAC,EAgBI,IAAMC,EAAW,eAAa,KAAK,EAC7BC,EAAU,CACd,OAAQ,GAAK,GAAK,GAAK,EACvB,KAAM,IACN,SAAU,EACZ,EAEMC,EAAe,IAAI,IAAIJ,EAAQ,OAAO,EAAE,aAAa,IAAI,OAAO,EAEtE,GAAII,EAAc,CAChB,IAAMC,EAAW,MAAM,MACrB,GAAGN,EAAa,YAAY,SAASA,EAAa,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"]}
|