@authdog/remix-node 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +8 -3
- package/dist/index.d.ts +8 -3
- 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/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -14,14 +14,19 @@ declare const createAuthResponse: (authenticatedUser: any, token: string, enviro
|
|
|
14
14
|
declare const authenticateWithCookies: (request: Request, publicKeyObj: any) => Promise<_remix_run_node.TypedResponse<{
|
|
15
15
|
user: any;
|
|
16
16
|
isAuthenticated: boolean;
|
|
17
|
+
signinUri: string;
|
|
17
18
|
}> | null>;
|
|
18
|
-
|
|
19
|
+
interface IRemixAuthLoader {
|
|
19
20
|
request: Request;
|
|
20
21
|
context: Record<string, any>;
|
|
21
|
-
params:
|
|
22
|
-
|
|
22
|
+
params: {
|
|
23
|
+
publicKey?: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
declare const remixAuthLoader: ({ request, context, params, }: IRemixAuthLoader) => Promise<_remix_run_node.TypedResponse<{
|
|
23
27
|
user: any;
|
|
24
28
|
isAuthenticated: boolean;
|
|
29
|
+
signinUri: string;
|
|
25
30
|
}>>;
|
|
26
31
|
|
|
27
32
|
export { AuthdogProvider, authenticateWithCookies, createAuthResponse, remixAuthLoader };
|
package/dist/index.d.ts
CHANGED
|
@@ -14,14 +14,19 @@ declare const createAuthResponse: (authenticatedUser: any, token: string, enviro
|
|
|
14
14
|
declare const authenticateWithCookies: (request: Request, publicKeyObj: any) => Promise<_remix_run_node.TypedResponse<{
|
|
15
15
|
user: any;
|
|
16
16
|
isAuthenticated: boolean;
|
|
17
|
+
signinUri: string;
|
|
17
18
|
}> | null>;
|
|
18
|
-
|
|
19
|
+
interface IRemixAuthLoader {
|
|
19
20
|
request: Request;
|
|
20
21
|
context: Record<string, any>;
|
|
21
|
-
params:
|
|
22
|
-
|
|
22
|
+
params: {
|
|
23
|
+
publicKey?: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
declare const remixAuthLoader: ({ request, context, params, }: IRemixAuthLoader) => Promise<_remix_run_node.TypedResponse<{
|
|
23
27
|
user: any;
|
|
24
28
|
isAuthenticated: boolean;
|
|
29
|
+
signinUri: string;
|
|
25
30
|
}>>;
|
|
26
31
|
|
|
27
32
|
export { AuthdogProvider, authenticateWithCookies, createAuthResponse, remixAuthLoader };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var
|
|
1
|
+
"use strict";var p=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var w=(o,e)=>{for(var n in e)p(o,n,{get:e[n],enumerable:!0})},C=(o,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of v(e))!S.call(o,t)&&t!==n&&p(o,t,{get:()=>e[t],enumerable:!(i=y(e,t))||i.enumerable});return o};var R=o=>C(p({},"__esModule",{value:!0}),o);var I={};w(I,{AuthdogProvider:()=>m,authenticateWithCookies:()=>A,createAuthResponse:()=>f,remixAuthLoader:()=>U});module.exports=R(I);var u=require("@remix-run/node"),c=require("@authdog/node-commons");var l=require("react"),g=require("react/jsx-runtime"),m=({children:o})=>{let[e,n]=(0,l.useState)(!0);return(0,l.useEffect)(()=>{if(typeof window<"u"){let i=new URL(window.location.href);if(i.searchParams.get("token")){i.searchParams.delete("token"),window.history.replaceState({},document.title,i.toString()),window.location.reload();return}n(!1)}},[]),e?null:(0,g.jsx)(g.Fragment,{children:o})};var f=(o,e,n,i)=>{console.log("[Authdog] Creating auth response with:",{hasUser:!!o?.user,environmentId:n,tokenLength:e?.length});let t=(0,u.json)({user:o.user,isAuthenticated:!0}),s=new Headers(t.headers),r=JSON.stringify(o?.user),d=e;console.log("[Authdog] Setting cookies for environment:",n),s.append("Set-Cookie",`user_session_${n}=${encodeURIComponent(r)}; Path=/; HttpOnly; Secure; SameSite=Strict`),s.append("Set-Cookie",`user_session_hash_${n}=${encodeURIComponent(d)}; Path=/; HttpOnly; Secure; SameSite=Strict`),s.append("Cache-Control","no-store, no-cache, must-revalidate, proxy-revalidate"),s.append("Pragma","no-cache"),s.append("Expires","0"),s.append("Vary","Cookie"),s.append("Content-Type","application/json"),s.append("Access-Control-Allow-Origin","*"),s.append("Access-Control-Allow-Credentials","true");let a=process.env.PK_AUTHDOG;if(!a)throw new Error("Public key is not defined");let h=(0,c.validateAndParsePublicKey)(a);return(0,u.json)({user:o.user,isAuthenticated:!0,signinUri:`${h.identityHost}/signin/${h.environmentId}`},{headers:s})},A=async(o,e)=>{try{console.log("[Authdog] Attempting cookie authentication for environment:",e?.environmentId);let n=o.headers.get("Cookie"),i=(0,c.parseCookies)(n);if(i.length===0)return console.log("[Authdog] No cookies found, returning unauthenticated"),(0,u.json)({user:null,isAuthenticated:!1,signinUri:`${e.identityHost}/signin/${e.environmentId}`});let t=i.find(s=>s.name===`user_session_hash_${e?.environmentId}`);if(t){console.log("[Authdog] Found session hash cookie, attempting to fetch user data");let s=t.value,r=await(0,c.fetchUserData)(e?.identityHost,e?.environmentId,s);return console.log("[Authdog] User data fetch result:",{success:!!r,hasUser:!!r?.user,metaCode:r?.meta?.code}),(0,u.json)({user:r.user,isAuthenticated:!0,signinUri:`${e.identityHost}/signin/${e.environmentId}`})}else console.log("[Authdog] No session hash cookie found for environment:",e?.environmentId)}catch(n){console.error("[Authdog] Error authenticating with cookies:",n)}return null},U=async({request:o,context:e,params:n})=>{console.log("[Authdog] Starting authentication loader");let i=typeof process<"u"?process.env.PK_AUTHDOG:n?.publicKey;if(!i)throw Error("[Authdog][Remix] Missing public key");let t=(0,c.validateAndParsePublicKey)(i);console.log("[Authdog] Public key parsed:",{hasPublicKey:!!i,environmentId:t?.environmentId});let r=new URL(o.url).searchParams.get("token");if(console.log("[Authdog] URL token check:",{hasToken:!!r,tokenLength:r?.length}),r){console.log("[Authdog] Processing token from URL");let a=await(0,c.fetchUserData)(t?.identityHost,t?.environmentId,r);if(console.log("[Authdog] Token authentication result:",{success:!!a,hasUser:!!a?.user,metaCode:a?.meta?.code}),a?.meta&&a?.meta?.code===200){let h=JSON.stringify(a?.user);e[`user_session_${t?.environmentId}`]=h,e[`user_session_hash_${t?.environmentId}`]=r;let k=f(a,r,t?.environmentId,o);return(0,u.json)({user:a.user,isAuthenticated:!0,signinUri:`${t.identityHost}/signin/${t.environmentId}`},{headers:k.headers})}}console.log("[Authdog] Attempting cookie authentication");let d=await A(o,t);return d?(console.log("[Authdog] Cookie authentication successful"),d):(console.log("[Authdog] No authentication methods succeeded, returning unauthenticated"),(0,u.json)({user:null,isAuthenticated:!1,signinUri:`${t.identityHost}/signin/${t.environmentId}`}))};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/provider.tsx"],"sourcesContent":["import { json } from \"@remix-run/node\";\n\nimport {\n parseCookies,\n validateAndParsePublicKey,\n fetchUserData,\n} from \"@authdog/node-commons\";\n\n// Function to create authentication response with cookies\nexport const createAuthResponse = (\n authenticatedUser: any,\n token: string,\n environmentId: string,\n request: Request,\n) => {\n\n\n console.log(\"[Authdog] Creating auth response with:\", {\n hasUser: !!authenticatedUser?.user,\n environmentId,\n tokenLength: token?.length,\n });\n\n // Create response with cookies\n const response = json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n });\n\n // Set cookies in the response headers\n const headers = new Headers(response.headers);\n\n // Serialize the user object separately\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n const userSessionHashValue = token;\n\n console.log(\"[Authdog] Setting cookies for environment:\", environmentId);\n\n headers.append(\n \"Set-Cookie\",\n `user_session_${environmentId}=${encodeURIComponent(userSessionValue)}; Path=/; HttpOnly; Secure; SameSite=Strict`,\n );\n headers.append(\n \"Set-Cookie\",\n `user_session_hash_${environmentId}=${encodeURIComponent(userSessionHashValue)}; Path=/; HttpOnly; Secure; SameSite=Strict`,\n );\n\n // Add cache control headers\n headers.append(\n \"Cache-Control\",\n \"no-store, no-cache, must-revalidate, proxy-revalidate\",\n );\n headers.append(\"Pragma\", \"no-cache\");\n headers.append(\"Expires\", \"0\");\n headers.append(\"Vary\", \"Cookie\");\n headers.append(\"Content-Type\", \"application/json\");\n headers.append(\"Access-Control-Allow-Origin\", \"*\");\n headers.append(\"Access-Control-Allow-Credentials\", \"true\");\n\n const publicKey = process.env.PK_AUTHDOG as string;\n\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n\n const publicKeyObj = validateAndParsePublicKey(publicKey)\n\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n },\n {\n headers,\n },\n );\n};\n\n// Function to authenticate with cookies\nexport const authenticateWithCookies = async (\n request: Request,\n publicKeyObj: any,\n) => {\n try {\n console.log(\"[Authdog] Attempting cookie authentication for environment:\", publicKeyObj?.environmentId);\n \n // Get cookies from request\n const cookieHeader = request.headers.get(\"Cookie\");\n const cookies = parseCookies(cookieHeader);\n\n if (cookies.length === 0) {\n console.log(\"[Authdog] No cookies found, returning unauthenticated\");\n return json({\n user: null,\n isAuthenticated: false,\n });\n }\n\n // Find our specific cookies\n const userSessionHashCookie = cookies.find(\n (c: any) => c.name === `user_session_hash_${publicKeyObj?.environmentId}`,\n );\n\n if (userSessionHashCookie) {\n console.log(\"[Authdog] Found session hash cookie, attempting to fetch user data\");\n const userSessionHashValue = userSessionHashCookie.value;\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n userSessionHashValue,\n );\n\n console.log(\"[Authdog] User data fetch result:\", {\n success: !!authenticatedUser,\n hasUser: !!authenticatedUser?.user,\n metaCode: authenticatedUser?.meta?.code,\n });\n\n return json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n });\n } else {\n console.log(\"[Authdog] No session hash cookie found for environment:\", publicKeyObj?.environmentId);\n }\n } catch (error) {\n console.error(\"[Authdog] Error authenticating with cookies:\", error);\n }\n\n return null;\n};\n\n// Main loader function\nexport const remixAuthLoader = async ({\n request,\n context,\n params,\n}: {\n request: Request;\n context: Record<string, any>;\n params: any;\n}) => {\n console.log(\"[Authdog] Starting authentication loader\");\n \n const publicKey =\n typeof process !== \"undefined\"\n ? (process.env.PK_AUTHDOG as string)\n : params?.publicKey;\n const publicKeyObj = validateAndParsePublicKey(publicKey);\n\n console.log(\"[Authdog] Public key parsed:\", {\n hasPublicKey: !!publicKey,\n environmentId: publicKeyObj?.environmentId,\n });\n\n // First check if we have a token in the URL\n const url = new URL(request.url);\n const tokenFromUri = url.searchParams.get(\"token\");\n\n console.log(\"[Authdog] URL token check:\", {\n hasToken: !!tokenFromUri,\n tokenLength: tokenFromUri?.length,\n });\n\n // If we have a token in URL, process it first\n if (tokenFromUri) {\n console.log(\"[Authdog] Processing token from URL\");\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n tokenFromUri,\n );\n\n console.log(\"[Authdog] Token authentication result:\", {\n success: !!authenticatedUser,\n hasUser: !!authenticatedUser?.user,\n metaCode: authenticatedUser?.meta?.code,\n });\n\n if (authenticatedUser?.meta && authenticatedUser?.meta?.code === 200) {\n // Store in context for later use\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n context[`user_session_${publicKeyObj?.environmentId}`] = userSessionValue;\n context[`user_session_hash_${publicKeyObj?.environmentId}`] = tokenFromUri;\n\n // Create the response with auth data\n const authResponse = createAuthResponse(\n authenticatedUser,\n tokenFromUri,\n publicKeyObj?.environmentId,\n request,\n );\n\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n },\n {\n headers: authResponse.headers,\n },\n );\n }\n }\n\n // If no token in URL or token authentication failed, try cookie authentication\n console.log(\"[Authdog] Attempting cookie authentication\");\n const cookieAuthResult = await authenticateWithCookies(request, publicKeyObj);\n if (cookieAuthResult) {\n console.log(\"[Authdog] Cookie authentication successful\");\n return cookieAuthResult;\n }\n\n console.log(\"[Authdog] No authentication methods succeeded, returning unauthenticated\");\n // If we get here, we're not authenticated\n return json({\n user: null,\n isAuthenticated: false,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n });\n};\n\nexport { AuthdogProvider } from \"./provider.tsx\";\n","\"use client\";\nimport React, { useEffect, useState } from \"react\";\n\nexport const AuthdogProvider = ({\n children,\n}: {\n children: React.ReactNode;\n}) => {\n const [isLoading, setIsLoading] = useState(true);\n\n useEffect(() => {\n // Check if we're in the browser\n if (typeof window !== \"undefined\") {\n // Check if there's a token in the URL\n const url = new URL(window.location.href);\n const token = url.searchParams.get(\"token\");\n\n if (token) {\n // Remove token from URL without triggering a page reload\n url.searchParams.delete(\"token\");\n window.history.replaceState({}, document.title, url.toString());\n\n // Force a reload to ensure the server processes the token\n window.location.reload();\n return;\n }\n\n // If no token, we're done loading\n setIsLoading(false);\n }\n }, []);\n\n // Show nothing while loading\n if (isLoading) {\n return null;\n }\n\n return <>{children}</>;\n};\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,4BAAAC,EAAA,uBAAAC,EAAA,oBAAAC,IAAA,eAAAC,EAAAN,GAAA,IAAAO,EAAqB,2BAErBC,EAIO,iCCLP,IAAAC,EAA2C,iBAoClCC,EAAA,6BAlCIC,EAAkB,CAAC,CAC9B,SAAAC,CACF,IAEM,CACJ,GAAM,CAACC,EAAWC,CAAY,KAAI,YAAS,EAAI,EAyB/C,SAvBA,aAAU,IAAM,CAEd,GAAI,OAAO,OAAW,IAAa,CAEjC,IAAMC,EAAM,IAAI,IAAI,OAAO,SA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AU,CAAC,CAACgB,EACZ,YAAaA,GAAc,MAC7B,CAAC,EAGGA,EAAc,CAChB,QAAQ,IAAI,qCAAqC,EACjD,IAAMnB,EAAoB,QAAM,iBAC9BS,GAAc,aACdA,GAAc,cACdU,CACF,EAQA,GANA,QAAQ,IAAI,yCAA0C,CACpD,QAAS,CAAC,CAACnB,EACX,QAAS,CAAC,CAACA,GAAmB,KAC9B,SAAUA,GAAmB,MAAM,IACrC,CAAC,EAEGA,GAAmB,MAAQA,GAAmB,MAAM,OAAS,IAAK,CAEpE,IAAMM,EAAmB,KAAK,UAAUN,GAAmB,IAAI,EAC/DiB,EAAQ,gBAAgBR,GAAc,aAAa,EAAE,EAAIH,EACzDW,EAAQ,qBAAqBR,GAAc,aAAa,EAAE,EAAIU,EAG9D,IAAMC,EAAerB,EACnBC,EACAmB,EACAV,GAAc,cACdN,CACF,EAEA,SAAO,QACL,CACE,KAAMH,EAAkB,KACxB,gBAAiB,GACjB,UAAW,GAAGS,EAAa,YAAY,WAAWA,EAAa,aAAa,EAC9E,EACA,CACE,QAASW,EAAa,OACxB,CACF,CACF,CACF,CAGA,QAAQ,IAAI,4CAA4C,EACxD,IAAMC,EAAmB,MAAMX,EAAwBP,EAASM,CAAY,EAC5E,OAAIY,GACF,QAAQ,IAAI,4CAA4C,EACjDA,IAGT,QAAQ,IAAI,0EAA0E,KAE/E,QAAK,CACV,KAAM,KACN,gBAAiB,GACjB,UAAW,GAAGZ,EAAa,YAAY,WAAWA,EAAa,aAAa,EAC9E,CAAC,EACH","names":["index_exports","__export","AuthdogProvider","authenticateWithCookies","createAuthResponse","remixAuthLoader","__toCommonJS","import_node","import_node_commons","import_react","import_jsx_runtime","AuthdogProvider","children","isLoading","setIsLoading","url","createAuthResponse","authenticatedUser","token","environmentId","request","response","headers","userSessionValue","userSessionHashValue","publicKey","publicKeyObj","authenticateWithCookies","cookieHeader","cookies","userSessionHashCookie","c","error","remixAuthLoader","context","params","tokenFromUri","authResponse","cookieAuthResult"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/provider.tsx"],"sourcesContent":["import { json } from \"@remix-run/node\";\n\nimport {\n parseCookies,\n validateAndParsePublicKey,\n fetchUserData,\n} from \"@authdog/node-commons\";\n\n// Function to create authentication response with cookies\nexport const createAuthResponse = (\n authenticatedUser: any,\n token: string,\n environmentId: string,\n request: Request,\n) => {\n\n\n console.log(\"[Authdog] Creating auth response with:\", {\n hasUser: !!authenticatedUser?.user,\n environmentId,\n tokenLength: token?.length,\n });\n\n // Create response with cookies\n const response = json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n });\n\n // Set cookies in the response headers\n const headers = new Headers(response.headers);\n\n // Serialize the user object separately\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n const userSessionHashValue = token;\n\n console.log(\"[Authdog] Setting cookies for environment:\", environmentId);\n\n headers.append(\n \"Set-Cookie\",\n `user_session_${environmentId}=${encodeURIComponent(userSessionValue)}; Path=/; HttpOnly; Secure; SameSite=Strict`,\n );\n headers.append(\n \"Set-Cookie\",\n `user_session_hash_${environmentId}=${encodeURIComponent(userSessionHashValue)}; Path=/; HttpOnly; Secure; SameSite=Strict`,\n );\n\n // Add cache control headers\n headers.append(\n \"Cache-Control\",\n \"no-store, no-cache, must-revalidate, proxy-revalidate\",\n );\n headers.append(\"Pragma\", \"no-cache\");\n headers.append(\"Expires\", \"0\");\n headers.append(\"Vary\", \"Cookie\");\n headers.append(\"Content-Type\", \"application/json\");\n headers.append(\"Access-Control-Allow-Origin\", \"*\");\n headers.append(\"Access-Control-Allow-Credentials\", \"true\");\n\n const publicKey = process.env.PK_AUTHDOG as string;\n\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n\n const publicKeyObj = validateAndParsePublicKey(publicKey)\n\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n },\n {\n headers,\n },\n );\n};\n\n// Function to authenticate with cookies\nexport const authenticateWithCookies = async (\n request: Request,\n publicKeyObj: any,\n) => {\n try {\n console.log(\"[Authdog] Attempting cookie authentication for environment:\", publicKeyObj?.environmentId);\n \n // Get cookies from request\n const cookieHeader = request.headers.get(\"Cookie\");\n const cookies = parseCookies(cookieHeader);\n\n if (cookies.length === 0) {\n console.log(\"[Authdog] No cookies found, returning unauthenticated\");\n return json({\n user: null,\n isAuthenticated: false,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n });\n }\n\n // Find our specific cookies\n const userSessionHashCookie = cookies.find(\n (c: any) => c.name === `user_session_hash_${publicKeyObj?.environmentId}`,\n );\n\n if (userSessionHashCookie) {\n console.log(\"[Authdog] Found session hash cookie, attempting to fetch user data\");\n const userSessionHashValue = userSessionHashCookie.value;\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n userSessionHashValue,\n );\n\n console.log(\"[Authdog] User data fetch result:\", {\n success: !!authenticatedUser,\n hasUser: !!authenticatedUser?.user,\n metaCode: authenticatedUser?.meta?.code,\n });\n\n return json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n\n });\n } else {\n console.log(\"[Authdog] No session hash cookie found for environment:\", publicKeyObj?.environmentId);\n }\n } catch (error) {\n console.error(\"[Authdog] Error authenticating with cookies:\", error);\n }\n\n return null;\n};\n\ninterface IRemixAuthLoader {\n request: Request;\n context: Record<string, any>;\n params: {\n publicKey?: string;\n }\n}\n\n// Main loader function\nexport const remixAuthLoader = async ({\n request,\n context,\n params,\n}: IRemixAuthLoader) => {\n console.log(\"[Authdog] Starting authentication loader\");\n \n const publicKey =\n typeof process !== \"undefined\"\n ? (process.env.PK_AUTHDOG as string)\n : params?.publicKey as string\n\n if (!publicKey) {\n throw Error(\"[Authdog][Remix] Missing public key\")\n }\n\n const publicKeyObj = validateAndParsePublicKey(publicKey);\n\n console.log(\"[Authdog] Public key parsed:\", {\n hasPublicKey: !!publicKey,\n environmentId: publicKeyObj?.environmentId,\n });\n\n // First check if we have a token in the URL\n const url = new URL(request.url);\n const tokenFromUri = url.searchParams.get(\"token\");\n\n console.log(\"[Authdog] URL token check:\", {\n hasToken: !!tokenFromUri,\n tokenLength: tokenFromUri?.length,\n });\n\n // If we have a token in URL, process it first\n if (tokenFromUri) {\n console.log(\"[Authdog] Processing token from URL\");\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n tokenFromUri,\n );\n\n console.log(\"[Authdog] Token authentication result:\", {\n success: !!authenticatedUser,\n hasUser: !!authenticatedUser?.user,\n metaCode: authenticatedUser?.meta?.code,\n });\n\n if (authenticatedUser?.meta && authenticatedUser?.meta?.code === 200) {\n // Store in context for later use\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n context[`user_session_${publicKeyObj?.environmentId}`] = userSessionValue;\n context[`user_session_hash_${publicKeyObj?.environmentId}`] = tokenFromUri;\n\n // Create the response with auth data\n const authResponse = createAuthResponse(\n authenticatedUser,\n tokenFromUri,\n publicKeyObj?.environmentId,\n request,\n );\n\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n },\n {\n headers: authResponse.headers,\n },\n );\n }\n }\n\n // If no token in URL or token authentication failed, try cookie authentication\n console.log(\"[Authdog] Attempting cookie authentication\");\n const cookieAuthResult = await authenticateWithCookies(request, publicKeyObj);\n if (cookieAuthResult) {\n console.log(\"[Authdog] Cookie authentication successful\");\n return cookieAuthResult;\n }\n\n console.log(\"[Authdog] No authentication methods succeeded, returning unauthenticated\");\n // If we get here, we're not authenticated\n return json({\n user: null,\n isAuthenticated: false,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n });\n};\n\nexport { AuthdogProvider } from \"./provider.tsx\";","\"use client\";\nimport React, { useEffect, useState } from \"react\";\n\nexport const AuthdogProvider = ({\n children,\n}: {\n children: React.ReactNode;\n}) => {\n const [isLoading, setIsLoading] = useState(true);\n\n useEffect(() => {\n // Check if we're in the browser\n if (typeof window !== \"undefined\") {\n // Check if there's a token in the URL\n const url = new URL(window.location.href);\n const token = url.searchParams.get(\"token\");\n\n if (token) {\n // Remove token from URL without triggering a page reload\n url.searchParams.delete(\"token\");\n window.history.replaceState({}, document.title, url.toString());\n\n // Force a reload to ensure the server processes the token\n window.location.reload();\n return;\n }\n\n // If no token, we're done loading\n setIsLoading(false);\n }\n }, []);\n\n // Show nothing while loading\n if (isLoading) {\n return null;\n }\n\n return <>{children}</>;\n};\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,4BAAAC,EAAA,uBAAAC,EAAA,oBAAAC,IAAA,eAAAC,EAAAN,GAAA,IAAAO,EAAqB,2BAErBC,EAIO,iCCLP,IAAAC,EAA2C,iBAoClCC,EAAA,6BAlCIC,EAAkB,CAAC,CAC9B,SAAAC,CACF,IAEM,CACJ,GAAM,CAACC,EAAWC,CAAY,KAAI,YAAS,EAAI,EAyB/C,SAvBA,aAAU,IAAM,CAEd,GAAI,OAAO,OAAW,IAAa,CAEjC,IAAMC,EAAM,IAAI,IAAI,OAAO,SAAS,IAAI,EAGxC,GAFcA,EAAI,aAAa,IAAI,OAAO,EAE/B,CAETA,EAAI,aAAa,OAAO,OAAO,EAC/B,OAAO,QAAQ,aAAa,CAAC,EAAG,SAAS,MAAOA,EAAI,SAAS,CAAC,EAG9D,OAAO,SAAS,OAAO,EACvB,MACF,CAGAD,EAAa,EAAK,CACpB,CACF,EAAG,CAAC,CAAC,EAGDD,EACK,QAGF,mBAAG,SAAAD,EAAS,CACrB,ED7BO,IAAMI,EAAqB,CAChCC,EACAC,EACAC,EACAC,IACG,CAGH,QAAQ,IAAI,yCAA0C,CACpD,QAAS,CAAC,CAACH,GAAmB,KAC9B,cAAAE,EACA,YAAaD,GAAO,MACtB,CAAC,EAGD,IA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GAAmB,MAAQA,GAAmB,MAAM,OAAS,IAAK,CAEpE,IAAMM,EAAmB,KAAK,UAAUN,GAAmB,IAAI,EAC/DiB,EAAQ,gBAAgBR,GAAc,aAAa,EAAE,EAAIH,EACzDW,EAAQ,qBAAqBR,GAAc,aAAa,EAAE,EAAIU,EAG9D,IAAMC,EAAerB,EACnBC,EACAmB,EACAV,GAAc,cACdN,CACF,EAEA,SAAO,QACL,CACE,KAAMH,EAAkB,KACxB,gBAAiB,GACjB,UAAW,GAAGS,EAAa,YAAY,WAAWA,EAAa,aAAa,EAC9E,EACA,CACE,QAASW,EAAa,OACxB,CACF,CACF,CACF,CAGA,QAAQ,IAAI,4CAA4C,EACxD,IAAMC,EAAmB,MAAMX,EAAwBP,EAASM,CAAY,EAC5E,OAAIY,GACF,QAAQ,IAAI,4CAA4C,EACjDA,IAGT,QAAQ,IAAI,0EAA0E,KAE/E,QAAK,CACV,KAAM,KACN,gBAAiB,GACjB,UAAW,GAAGZ,EAAa,YAAY,WAAWA,EAAa,aAAa,EAC9E,CAAC,EACH","names":["index_exports","__export","AuthdogProvider","authenticateWithCookies","createAuthResponse","remixAuthLoader","__toCommonJS","import_node","import_node_commons","import_react","import_jsx_runtime","AuthdogProvider","children","isLoading","setIsLoading","url","createAuthResponse","authenticatedUser","token","environmentId","request","response","headers","userSessionValue","userSessionHashValue","publicKey","publicKeyObj","authenticateWithCookies","cookieHeader","cookies","userSessionHashCookie","c","error","remixAuthLoader","context","params","tokenFromUri","authResponse","cookieAuthResult"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{json as c}from"@remix-run/node";import{parseCookies as y,validateAndParsePublicKey as h,fetchUserData as l}from"@authdog/node-commons";import{useEffect as p,useState as m}from"react";import{Fragment as A,jsx as k}from"react/jsx-runtime";var f=({children:s})=>{let[
|
|
1
|
+
import{json as c}from"@remix-run/node";import{parseCookies as y,validateAndParsePublicKey as h,fetchUserData as l}from"@authdog/node-commons";import{useEffect as p,useState as m}from"react";import{Fragment as A,jsx as k}from"react/jsx-runtime";var f=({children:s})=>{let[e,i]=m(!0);return p(()=>{if(typeof window<"u"){let r=new URL(window.location.href);if(r.searchParams.get("token")){r.searchParams.delete("token"),window.history.replaceState({},document.title,r.toString()),window.location.reload();return}i(!1)}},[]),e?null:k(A,{children:s})};var v=(s,e,i,r)=>{console.log("[Authdog] Creating auth response with:",{hasUser:!!s?.user,environmentId:i,tokenLength:e?.length});let t=c({user:s.user,isAuthenticated:!0}),o=new Headers(t.headers),n=JSON.stringify(s?.user),u=e;console.log("[Authdog] Setting cookies for environment:",i),o.append("Set-Cookie",`user_session_${i}=${encodeURIComponent(n)}; Path=/; HttpOnly; Secure; SameSite=Strict`),o.append("Set-Cookie",`user_session_hash_${i}=${encodeURIComponent(u)}; Path=/; HttpOnly; Secure; SameSite=Strict`),o.append("Cache-Control","no-store, no-cache, must-revalidate, proxy-revalidate"),o.append("Pragma","no-cache"),o.append("Expires","0"),o.append("Vary","Cookie"),o.append("Content-Type","application/json"),o.append("Access-Control-Allow-Origin","*"),o.append("Access-Control-Allow-Credentials","true");let a=process.env.PK_AUTHDOG;if(!a)throw new Error("Public key is not defined");let d=h(a);return c({user:s.user,isAuthenticated:!0,signinUri:`${d.identityHost}/signin/${d.environmentId}`},{headers:o})},S=async(s,e)=>{try{console.log("[Authdog] Attempting cookie authentication for environment:",e?.environmentId);let i=s.headers.get("Cookie"),r=y(i);if(r.length===0)return console.log("[Authdog] No cookies found, returning unauthenticated"),c({user:null,isAuthenticated:!1,signinUri:`${e.identityHost}/signin/${e.environmentId}`});let t=r.find(o=>o.name===`user_session_hash_${e?.environmentId}`);if(t){console.log("[Authdog] Found session hash cookie, attempting to fetch user data");let o=t.value,n=await l(e?.identityHost,e?.environmentId,o);return console.log("[Authdog] User data fetch result:",{success:!!n,hasUser:!!n?.user,metaCode:n?.meta?.code}),c({user:n.user,isAuthenticated:!0,signinUri:`${e.identityHost}/signin/${e.environmentId}`})}else console.log("[Authdog] No session hash cookie found for environment:",e?.environmentId)}catch(i){console.error("[Authdog] Error authenticating with cookies:",i)}return null},H=async({request:s,context:e,params:i})=>{console.log("[Authdog] Starting authentication loader");let r=typeof process<"u"?process.env.PK_AUTHDOG:i?.publicKey;if(!r)throw Error("[Authdog][Remix] Missing public key");let t=h(r);console.log("[Authdog] Public key parsed:",{hasPublicKey:!!r,environmentId:t?.environmentId});let n=new URL(s.url).searchParams.get("token");if(console.log("[Authdog] URL token check:",{hasToken:!!n,tokenLength:n?.length}),n){console.log("[Authdog] Processing token from URL");let a=await l(t?.identityHost,t?.environmentId,n);if(console.log("[Authdog] Token authentication result:",{success:!!a,hasUser:!!a?.user,metaCode:a?.meta?.code}),a?.meta&&a?.meta?.code===200){let d=JSON.stringify(a?.user);e[`user_session_${t?.environmentId}`]=d,e[`user_session_hash_${t?.environmentId}`]=n;let g=v(a,n,t?.environmentId,s);return c({user:a.user,isAuthenticated:!0,signinUri:`${t.identityHost}/signin/${t.environmentId}`},{headers:g.headers})}}console.log("[Authdog] Attempting cookie authentication");let u=await S(s,t);return u?(console.log("[Authdog] Cookie authentication successful"),u):(console.log("[Authdog] No authentication methods succeeded, returning unauthenticated"),c({user:null,isAuthenticated:!1,signinUri:`${t.identityHost}/signin/${t.environmentId}`}))};export{f as AuthdogProvider,S as authenticateWithCookies,v as createAuthResponse,H as remixAuthLoader};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/provider.tsx"],"sourcesContent":["import { json } from \"@remix-run/node\";\n\nimport {\n parseCookies,\n validateAndParsePublicKey,\n fetchUserData,\n} from \"@authdog/node-commons\";\n\n// Function to create authentication response with cookies\nexport const createAuthResponse = (\n authenticatedUser: any,\n token: string,\n environmentId: string,\n request: Request,\n) => {\n\n\n console.log(\"[Authdog] Creating auth response with:\", {\n hasUser: !!authenticatedUser?.user,\n environmentId,\n tokenLength: token?.length,\n });\n\n // Create response with cookies\n const response = json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n });\n\n // Set cookies in the response headers\n const headers = new Headers(response.headers);\n\n // Serialize the user object separately\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n const userSessionHashValue = token;\n\n console.log(\"[Authdog] Setting cookies for environment:\", environmentId);\n\n headers.append(\n \"Set-Cookie\",\n `user_session_${environmentId}=${encodeURIComponent(userSessionValue)}; Path=/; HttpOnly; Secure; SameSite=Strict`,\n );\n headers.append(\n \"Set-Cookie\",\n `user_session_hash_${environmentId}=${encodeURIComponent(userSessionHashValue)}; Path=/; HttpOnly; Secure; SameSite=Strict`,\n );\n\n // Add cache control headers\n headers.append(\n \"Cache-Control\",\n \"no-store, no-cache, must-revalidate, proxy-revalidate\",\n );\n headers.append(\"Pragma\", \"no-cache\");\n headers.append(\"Expires\", \"0\");\n headers.append(\"Vary\", \"Cookie\");\n headers.append(\"Content-Type\", \"application/json\");\n headers.append(\"Access-Control-Allow-Origin\", \"*\");\n headers.append(\"Access-Control-Allow-Credentials\", \"true\");\n\n const publicKey = process.env.PK_AUTHDOG as string;\n\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n\n const publicKeyObj = validateAndParsePublicKey(publicKey)\n\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n },\n {\n headers,\n },\n );\n};\n\n// Function to authenticate with cookies\nexport const authenticateWithCookies = async (\n request: Request,\n publicKeyObj: any,\n) => {\n try {\n console.log(\"[Authdog] Attempting cookie authentication for environment:\", publicKeyObj?.environmentId);\n \n // Get cookies from request\n const cookieHeader = request.headers.get(\"Cookie\");\n const cookies = parseCookies(cookieHeader);\n\n if (cookies.length === 0) {\n console.log(\"[Authdog] No cookies found, returning unauthenticated\");\n return json({\n user: null,\n isAuthenticated: false,\n });\n }\n\n // Find our specific cookies\n const userSessionHashCookie = cookies.find(\n (c: any) => c.name === `user_session_hash_${publicKeyObj?.environmentId}`,\n );\n\n if (userSessionHashCookie) {\n console.log(\"[Authdog] Found session hash cookie, attempting to fetch user data\");\n const userSessionHashValue = userSessionHashCookie.value;\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n userSessionHashValue,\n );\n\n console.log(\"[Authdog] User data fetch result:\", {\n success: !!authenticatedUser,\n hasUser: !!authenticatedUser?.user,\n metaCode: authenticatedUser?.meta?.code,\n });\n\n return json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n });\n } else {\n console.log(\"[Authdog] No session hash cookie found for environment:\", publicKeyObj?.environmentId);\n }\n } catch (error) {\n console.error(\"[Authdog] Error authenticating with cookies:\", error);\n }\n\n return null;\n};\n\n// Main loader function\nexport const remixAuthLoader = async ({\n request,\n context,\n params,\n}: {\n request: Request;\n context: Record<string, any>;\n params: any;\n}) => {\n console.log(\"[Authdog] Starting authentication loader\");\n \n const publicKey =\n typeof process !== \"undefined\"\n ? (process.env.PK_AUTHDOG as string)\n : params?.publicKey;\n const publicKeyObj = validateAndParsePublicKey(publicKey);\n\n console.log(\"[Authdog] Public key parsed:\", {\n hasPublicKey: !!publicKey,\n environmentId: publicKeyObj?.environmentId,\n });\n\n // First check if we have a token in the URL\n const url = new URL(request.url);\n const tokenFromUri = url.searchParams.get(\"token\");\n\n console.log(\"[Authdog] URL token check:\", {\n hasToken: !!tokenFromUri,\n tokenLength: tokenFromUri?.length,\n });\n\n // If we have a token in URL, process it first\n if (tokenFromUri) {\n console.log(\"[Authdog] Processing token from URL\");\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n tokenFromUri,\n );\n\n console.log(\"[Authdog] Token authentication result:\", {\n success: !!authenticatedUser,\n hasUser: !!authenticatedUser?.user,\n metaCode: authenticatedUser?.meta?.code,\n });\n\n if (authenticatedUser?.meta && authenticatedUser?.meta?.code === 200) {\n // Store in context for later use\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n context[`user_session_${publicKeyObj?.environmentId}`] = userSessionValue;\n context[`user_session_hash_${publicKeyObj?.environmentId}`] = tokenFromUri;\n\n // Create the response with auth data\n const authResponse = createAuthResponse(\n authenticatedUser,\n tokenFromUri,\n publicKeyObj?.environmentId,\n request,\n );\n\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n },\n {\n headers: authResponse.headers,\n },\n );\n }\n }\n\n // If no token in URL or token authentication failed, try cookie authentication\n console.log(\"[Authdog] Attempting cookie authentication\");\n const cookieAuthResult = await authenticateWithCookies(request, publicKeyObj);\n if (cookieAuthResult) {\n console.log(\"[Authdog] Cookie authentication successful\");\n return cookieAuthResult;\n }\n\n console.log(\"[Authdog] No authentication methods succeeded, returning unauthenticated\");\n // If we get here, we're not authenticated\n return json({\n user: null,\n isAuthenticated: false,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n });\n};\n\nexport { AuthdogProvider } from \"./provider.tsx\";\n","\"use client\";\nimport React, { useEffect, useState } from \"react\";\n\nexport const AuthdogProvider = ({\n children,\n}: {\n children: React.ReactNode;\n}) => {\n const [isLoading, setIsLoading] = useState(true);\n\n useEffect(() => {\n // Check if we're in the browser\n if (typeof window !== \"undefined\") {\n // Check if there's a token in the URL\n const url = new URL(window.location.href);\n const token = url.searchParams.get(\"token\");\n\n if (token) {\n // Remove token from URL without triggering a page reload\n url.searchParams.delete(\"token\");\n window.history.replaceState({}, document.title, url.toString());\n\n // Force a reload to ensure the server processes the token\n window.location.reload();\n return;\n }\n\n // If no token, we're done loading\n setIsLoading(false);\n }\n }, []);\n\n // Show nothing while loading\n if (isLoading) {\n return null;\n }\n\n return <>{children}</>;\n};\n"],"mappings":"AAAA,OAAS,QAAAA,MAAY,kBAErB,OACE,gBAAAC,EACA,6BAAAC,EACA,iBAAAC,MACK,wBCLP,OAAgB,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CAAC,EACH","names":["json","parseCookies","validateAndParsePublicKey","fetchUserData","useEffect","useState","Fragment","jsx","AuthdogProvider","children","isLoading","setIsLoading","url","createAuthResponse","authenticatedUser","token","environmentId","request","response","json","headers","userSessionValue","userSessionHashValue","publicKey","publicKeyObj","validateAndParsePublicKey","authenticateWithCookies","cookieHeader","cookies","parseCookies","userSessionHashCookie","c","fetchUserData","error","remixAuthLoader","context","params","tokenFromUri","authResponse","cookieAuthResult"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/provider.tsx"],"sourcesContent":["import { json } from \"@remix-run/node\";\n\nimport {\n parseCookies,\n validateAndParsePublicKey,\n fetchUserData,\n} from \"@authdog/node-commons\";\n\n// Function to create authentication response with cookies\nexport const createAuthResponse = (\n authenticatedUser: any,\n token: string,\n environmentId: string,\n request: Request,\n) => {\n\n\n console.log(\"[Authdog] Creating auth response with:\", {\n hasUser: !!authenticatedUser?.user,\n environmentId,\n tokenLength: token?.length,\n });\n\n // Create response with cookies\n const response = json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n });\n\n // Set cookies in the response headers\n const headers = new Headers(response.headers);\n\n // Serialize the user object separately\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n const userSessionHashValue = token;\n\n console.log(\"[Authdog] Setting cookies for environment:\", environmentId);\n\n headers.append(\n \"Set-Cookie\",\n `user_session_${environmentId}=${encodeURIComponent(userSessionValue)}; Path=/; HttpOnly; Secure; SameSite=Strict`,\n );\n headers.append(\n \"Set-Cookie\",\n `user_session_hash_${environmentId}=${encodeURIComponent(userSessionHashValue)}; Path=/; HttpOnly; Secure; SameSite=Strict`,\n );\n\n // Add cache control headers\n headers.append(\n \"Cache-Control\",\n \"no-store, no-cache, must-revalidate, proxy-revalidate\",\n );\n headers.append(\"Pragma\", \"no-cache\");\n headers.append(\"Expires\", \"0\");\n headers.append(\"Vary\", \"Cookie\");\n headers.append(\"Content-Type\", \"application/json\");\n headers.append(\"Access-Control-Allow-Origin\", \"*\");\n headers.append(\"Access-Control-Allow-Credentials\", \"true\");\n\n const publicKey = process.env.PK_AUTHDOG as string;\n\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n\n const publicKeyObj = validateAndParsePublicKey(publicKey)\n\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n },\n {\n headers,\n },\n );\n};\n\n// Function to authenticate with cookies\nexport const authenticateWithCookies = async (\n request: Request,\n publicKeyObj: any,\n) => {\n try {\n console.log(\"[Authdog] Attempting cookie authentication for environment:\", publicKeyObj?.environmentId);\n \n // Get cookies from request\n const cookieHeader = request.headers.get(\"Cookie\");\n const cookies = parseCookies(cookieHeader);\n\n if (cookies.length === 0) {\n console.log(\"[Authdog] No cookies found, returning unauthenticated\");\n return json({\n user: null,\n isAuthenticated: false,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n });\n }\n\n // Find our specific cookies\n const userSessionHashCookie = cookies.find(\n (c: any) => c.name === `user_session_hash_${publicKeyObj?.environmentId}`,\n );\n\n if (userSessionHashCookie) {\n console.log(\"[Authdog] Found session hash cookie, attempting to fetch user data\");\n const userSessionHashValue = userSessionHashCookie.value;\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n userSessionHashValue,\n );\n\n console.log(\"[Authdog] User data fetch result:\", {\n success: !!authenticatedUser,\n hasUser: !!authenticatedUser?.user,\n metaCode: authenticatedUser?.meta?.code,\n });\n\n return json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n\n });\n } else {\n console.log(\"[Authdog] No session hash cookie found for environment:\", publicKeyObj?.environmentId);\n }\n } catch (error) {\n console.error(\"[Authdog] Error authenticating with cookies:\", error);\n }\n\n return null;\n};\n\ninterface IRemixAuthLoader {\n request: Request;\n context: Record<string, any>;\n params: {\n publicKey?: string;\n }\n}\n\n// Main loader function\nexport const remixAuthLoader = async ({\n request,\n context,\n params,\n}: IRemixAuthLoader) => {\n console.log(\"[Authdog] Starting authentication loader\");\n \n const publicKey =\n typeof process !== \"undefined\"\n ? (process.env.PK_AUTHDOG as string)\n : params?.publicKey as string\n\n if (!publicKey) {\n throw Error(\"[Authdog][Remix] Missing public key\")\n }\n\n const publicKeyObj = validateAndParsePublicKey(publicKey);\n\n console.log(\"[Authdog] Public key parsed:\", {\n hasPublicKey: !!publicKey,\n environmentId: publicKeyObj?.environmentId,\n });\n\n // First check if we have a token in the URL\n const url = new URL(request.url);\n const tokenFromUri = url.searchParams.get(\"token\");\n\n console.log(\"[Authdog] URL token check:\", {\n hasToken: !!tokenFromUri,\n tokenLength: tokenFromUri?.length,\n });\n\n // If we have a token in URL, process it first\n if (tokenFromUri) {\n console.log(\"[Authdog] Processing token from URL\");\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n tokenFromUri,\n );\n\n console.log(\"[Authdog] Token authentication result:\", {\n success: !!authenticatedUser,\n hasUser: !!authenticatedUser?.user,\n metaCode: authenticatedUser?.meta?.code,\n });\n\n if (authenticatedUser?.meta && authenticatedUser?.meta?.code === 200) {\n // Store in context for later use\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n context[`user_session_${publicKeyObj?.environmentId}`] = userSessionValue;\n context[`user_session_hash_${publicKeyObj?.environmentId}`] = tokenFromUri;\n\n // Create the response with auth data\n const authResponse = createAuthResponse(\n authenticatedUser,\n tokenFromUri,\n publicKeyObj?.environmentId,\n request,\n );\n\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n },\n {\n headers: authResponse.headers,\n },\n );\n }\n }\n\n // If no token in URL or token authentication failed, try cookie authentication\n console.log(\"[Authdog] Attempting cookie authentication\");\n const cookieAuthResult = await authenticateWithCookies(request, publicKeyObj);\n if (cookieAuthResult) {\n console.log(\"[Authdog] Cookie authentication successful\");\n return cookieAuthResult;\n }\n\n console.log(\"[Authdog] No authentication methods succeeded, returning unauthenticated\");\n // If we get here, we're not authenticated\n return json({\n user: null,\n isAuthenticated: false,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n });\n};\n\nexport { AuthdogProvider } from \"./provider.tsx\";","\"use client\";\nimport React, { useEffect, useState } from \"react\";\n\nexport const AuthdogProvider = ({\n children,\n}: {\n children: React.ReactNode;\n}) => {\n const [isLoading, setIsLoading] = useState(true);\n\n useEffect(() => {\n // Check if we're in the browser\n if (typeof window !== \"undefined\") {\n // Check if there's a token in the URL\n const url = new URL(window.location.href);\n const token = url.searchParams.get(\"token\");\n\n if (token) {\n // Remove token from URL without triggering a page reload\n url.searchParams.delete(\"token\");\n window.history.replaceState({}, document.title, url.toString());\n\n // Force a reload to ensure the server processes the token\n window.location.reload();\n return;\n }\n\n // If no token, we're done loading\n setIsLoading(false);\n }\n }, []);\n\n // Show nothing while loading\n if (isLoading) {\n return null;\n }\n\n return <>{children}</>;\n};\n"],"mappings":"AAAA,OAAS,QAAAA,MAAY,kBAErB,OACE,gBAAAC,EACA,6BAAAC,EACA,iBAAAC,MACK,wBCLP,OAAgB,aAAAC,EAAW,YAAAC,MAAgB,QAoClC,mBAAAC,EAAA,OAAAC,MAAA,oBAlCF,IAAMC,EAAkB,CAAC,CAC9B,SAAAC,CACF,IAEM,CACJ,GAAM,CAACC,EAAWC,CAAY,EAAIN,EAAS,EAAI,EAyB/C,OAvBAD,EAAU,IAAM,CAEd,GAAI,OAAO,OAAW,IAAa,CAEjC,IAAMQ,EAAM,IAAI,IAAI,OAAO,SAAS,IAAI,EAGxC,GAFcA,EAAI,aAAa,IAAI,OAAO,EAE/B,CAETA,EAAI,aAAa,OAAO,OAAO,EAC/B,OAAO,QAAQ,aAAa,CAAC,EAAG,SAAS,MAAOA,EAAI,SAAS,CAAC,EAG9D,OAAO,SAAS,OAAO,E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U,CAAC,CAACoB,EACZ,YAAaA,GAAc,MAC7B,CAAC,EAGGA,EAAc,CAChB,QAAQ,IAAI,qCAAqC,EACjD,IAAMvB,EAAoB,MAAMkB,EAC9BR,GAAc,aACdA,GAAc,cACda,CACF,EAQA,GANA,QAAQ,IAAI,yCAA0C,CACpD,QAAS,CAAC,CAACvB,EACX,QAAS,CAAC,CAACA,GAAmB,KAC9B,SAAUA,GAAmB,MAAM,IACrC,CAAC,EAEGA,GAAmB,MAAQA,GAAmB,MAAM,OAAS,IAAK,CAEpE,IAAMO,EAAmB,KAAK,UAAUP,GAAmB,IAAI,EAC/DqB,EAAQ,gBAAgBX,GAAc,aAAa,EAAE,EAAIH,EACzDc,EAAQ,qBAAqBX,GAAc,aAAa,EAAE,EAAIa,EAG9D,IAAMC,EAAezB,EACnBC,EACAuB,EACAb,GAAc,cACdP,CACF,EAEA,OAAOE,EACL,CACE,KAAML,EAAkB,KACxB,gBAAiB,GACjB,UAAW,GAAGU,EAAa,YAAY,WAAWA,EAAa,aAAa,EAC9E,EACA,CACE,QAASc,EAAa,OACxB,CACF,CACF,CACF,CAGA,QAAQ,IAAI,4CAA4C,EACxD,IAAMC,EAAmB,MAAMb,EAAwBT,EAASO,CAAY,EAC5E,OAAIe,GACF,QAAQ,IAAI,4CAA4C,EACjDA,IAGT,QAAQ,IAAI,0EAA0E,EAE/EpB,EAAK,CACV,KAAM,KACN,gBAAiB,GACjB,UAAW,GAAGK,EAAa,YAAY,WAAWA,EAAa,aAAa,EAC9E,CAAC,EACH","names":["json","parseCookies","validateAndParsePublicKey","fetchUserData","useEffect","useState","Fragment","jsx","AuthdogProvider","children","isLoading","setIsLoading","url","createAuthResponse","authenticatedUser","token","environmentId","request","response","json","headers","userSessionValue","userSessionHashValue","publicKey","publicKeyObj","validateAndParsePublicKey","authenticateWithCookies","cookieHeader","cookies","parseCookies","userSessionHashCookie","c","fetchUserData","error","remixAuthLoader","context","params","tokenFromUri","authResponse","cookieAuthResult"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authdog/remix-node",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "Authdog Remix SDK",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@remix-run/node": "^2.15.2",
|
|
25
25
|
"@remix-run/react": "^2.16.5",
|
|
26
26
|
"react": "^18.2.0",
|
|
27
|
-
"@authdog/node-commons": "0.0.
|
|
27
|
+
"@authdog/node-commons": "0.0.22"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^22.14.1",
|