@authdog/remix-node 0.0.6 → 0.0.8

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 CHANGED
@@ -5,4 +5,3 @@ Authdog remix-node library
5
5
  ## Use session
6
6
 
7
7
  ## Loader
8
-
package/dist/index.d.mts CHANGED
@@ -2,27 +2,26 @@ import * as _remix_run_node from '@remix-run/node';
2
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
3
  import React from 'react';
4
4
 
5
- declare const AuthdogProvider: ({ children }: {
5
+ declare const AuthdogProvider: ({ children, }: {
6
6
  children: React.ReactNode;
7
7
  }) => react_jsx_runtime.JSX.Element | null;
8
8
 
9
9
  declare const createAuthResponse: (authenticatedUser: any, token: string, environmentId: string, request: Request) => _remix_run_node.TypedResponse<{
10
10
  user: any;
11
11
  isAuthenticated: boolean;
12
+ signinUri: string;
12
13
  }>;
13
14
  declare const authenticateWithCookies: (request: Request, publicKeyObj: any) => Promise<_remix_run_node.TypedResponse<{
14
15
  user: any;
15
16
  isAuthenticated: boolean;
16
17
  }> | null>;
17
- declare const remixAuthLoader: ({ request, context, params }: {
18
+ declare const remixAuthLoader: ({ request, context, params, }: {
18
19
  request: Request;
19
20
  context: Record<string, any>;
20
21
  params: any;
21
22
  }) => Promise<_remix_run_node.TypedResponse<{
22
23
  user: any;
23
24
  isAuthenticated: boolean;
24
- }> | _remix_run_node.TypedResponse<{
25
- loading: boolean;
26
25
  }>>;
27
26
 
28
27
  export { AuthdogProvider, authenticateWithCookies, createAuthResponse, remixAuthLoader };
package/dist/index.d.ts CHANGED
@@ -2,27 +2,26 @@ import * as _remix_run_node from '@remix-run/node';
2
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
3
  import React from 'react';
4
4
 
5
- declare const AuthdogProvider: ({ children }: {
5
+ declare const AuthdogProvider: ({ children, }: {
6
6
  children: React.ReactNode;
7
7
  }) => react_jsx_runtime.JSX.Element | null;
8
8
 
9
9
  declare const createAuthResponse: (authenticatedUser: any, token: string, environmentId: string, request: Request) => _remix_run_node.TypedResponse<{
10
10
  user: any;
11
11
  isAuthenticated: boolean;
12
+ signinUri: string;
12
13
  }>;
13
14
  declare const authenticateWithCookies: (request: Request, publicKeyObj: any) => Promise<_remix_run_node.TypedResponse<{
14
15
  user: any;
15
16
  isAuthenticated: boolean;
16
17
  }> | null>;
17
- declare const remixAuthLoader: ({ request, context, params }: {
18
+ declare const remixAuthLoader: ({ request, context, params, }: {
18
19
  request: Request;
19
20
  context: Record<string, any>;
20
21
  params: any;
21
22
  }) => Promise<_remix_run_node.TypedResponse<{
22
23
  user: any;
23
24
  isAuthenticated: boolean;
24
- }> | _remix_run_node.TypedResponse<{
25
- loading: boolean;
26
25
  }>>;
27
26
 
28
27
  export { AuthdogProvider, authenticateWithCookies, createAuthResponse, remixAuthLoader };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var f=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var k=(n,t)=>{for(var s in t)f(n,s,{get:t[s],enumerable:!0})},v=(n,t,s,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of w(t))!A.call(n,e)&&e!==s&&f(n,e,{get:()=>t[e],enumerable:!(o=_(t,e))||o.enumerable});return n};var C=n=>v(f({},"__esModule",{value:!0}),n);var I={};k(I,{AuthdogProvider:()=>S,authenticateWithCookies:()=>g,createAuthResponse:()=>y,remixAuthLoader:()=>R});module.exports=C(I);var u=require("@remix-run/node"),c=require("@authdog/node-commons");var h=require("react"),l=require("react/jsx-runtime"),S=({children:n})=>{let[t,s]=(0,h.useState)(!0);return(0,h.useEffect)(()=>{if(typeof window<"u"){let o=new URL(window.location.href);if(o.searchParams.get("token")){o.searchParams.delete("token"),window.history.replaceState({},document.title,o.toString()),window.location.reload();return}s(!1)}},[]),t?null:(0,l.jsx)(l.Fragment,{children:n})};var y=(n,t,s,o)=>{let e=(0,u.json)({user:n.user,isAuthenticated:!0}),r=new Headers(e.headers),i=JSON.stringify(n?.user),d=t;return r.append("Set-Cookie",`user_session_${s}=${encodeURIComponent(i)}; Path=/; HttpOnly; Secure; SameSite=Strict`),r.append("Set-Cookie",`user_session_hash_${s}=${encodeURIComponent(d)}; Path=/; HttpOnly; Secure; SameSite=Strict`),r.append("Cache-Control","no-store, no-cache, must-revalidate, proxy-revalidate"),r.append("Pragma","no-cache"),r.append("Expires","0"),r.append("Vary","Cookie"),r.append("Content-Type","application/json"),r.append("Access-Control-Allow-Origin","*"),r.append("Access-Control-Allow-Credentials","true"),(0,u.json)({user:n.user,isAuthenticated:!0},{headers:r})},g=async(n,t)=>{try{let s=n.headers.get("Cookie"),o=(0,c.parseCookies)(s);if(o.length===0)return(0,u.json)({user:null,isAuthenticated:!1});let e=o.find(r=>r.name===`user_session_hash_${t?.environmentId}`);if(e){let r=e.value,i=await(0,c.fetchUserData)(t?.identityHost,t?.environmentId,r);return(0,u.json)({user:i.user,isAuthenticated:!0})}}catch(s){console.error("Error authenticating with cookies:",s)}return null},R=async({request:n,context:t,params:s})=>{let o=typeof process<"u"?process.env.PK_AUTHDOG:s?.publicKey,e=(0,c.validateAndParsePublicKey)(o),i=new URL(n.url).searchParams.get("token"),d=await g(n,e);if(d){if(i){let a=await(0,c.fetchUserData)(e?.identityHost,e?.environmentId,i);if(a?.meta&&a?.meta?.code===200){let p=JSON.stringify(a?.user);t[`user_session_${e?.environmentId}`]=p,t[`user_session_hash_${e?.environmentId}`]=i;let m=y(a,i,e?.environmentId,n);return(0,u.json)({user:a.user,isAuthenticated:!0},{headers:m.headers})}}return d}if(i){let a=await(0,c.fetchUserData)(e?.identityHost,e?.environmentId,i);if(a?.meta&&a?.meta?.code===200){let p=JSON.stringify(a?.user);t[`user_session_${e?.environmentId}`]=p,t[`user_session_hash_${e?.environmentId}`]=i;let m=y(a,i,e?.environmentId,n);return(0,u.json)({user:a.user,isAuthenticated:!0},{headers:m.headers})}return(0,u.json)({loading:!0})}return(0,u.json)({user:null,isAuthenticated:!1})};
1
+ "use strict";var p=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var w=(o,e)=>{for(var n in e)p(o,n,{get:e[n],enumerable:!0})},C=(o,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of S(e))!v.call(o,t)&&t!==n&&p(o,t,{get:()=>e[t],enumerable:!(r=y(e,t))||r.enumerable});return o};var P=o=>C(p({},"__esModule",{value:!0}),o);var U={};w(U,{AuthdogProvider:()=>m,authenticateWithCookies:()=>A,createAuthResponse:()=>f,remixAuthLoader:()=>R});module.exports=P(U);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 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}n(!1)}},[]),e?null:(0,g.jsx)(g.Fragment,{children:o})};var f=(o,e,n,r)=>{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),i=JSON.stringify(o?.user),d=e;console.log("[Authdog] Setting cookies for environment:",n),s.append("Set-Cookie",`user_session_${n}=${encodeURIComponent(i)}; 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"),r=(0,c.parseCookies)(n);if(r.length===0)return console.log("[Authdog] No cookies found, returning unauthenticated"),(0,u.json)({user:null,isAuthenticated:!1});let t=r.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,i=await(0,c.fetchUserData)(e?.identityHost,e?.environmentId,s);return console.log("[Authdog] User data fetch result:",{success:!!i,hasUser:!!i?.user,metaCode:i?.meta?.code}),(0,u.json)({user:i.user,isAuthenticated:!0})}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},R=async({request:o,context:e,params:n})=>{console.log("[Authdog] Starting authentication loader");let r=typeof process<"u"?process.env.PK_AUTHDOG:n?.publicKey,t=(0,c.validateAndParsePublicKey)(r);console.log("[Authdog] Public key parsed:",{hasPublicKey:!!r,environmentId:t?.environmentId});let i=new URL(o.url).searchParams.get("token");if(console.log("[Authdog] URL token check:",{hasToken:!!i,tokenLength:i?.length}),i){console.log("[Authdog] Processing token from URL");let a=await(0,c.fetchUserData)(t?.identityHost,t?.environmentId,i);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}`]=i;let k=f(a,i,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 { parseCookies, validateAndParsePublicKey, fetchUserData } 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 // 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 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 return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\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 // Get cookies from request\n const cookieHeader = request.headers.get(\"Cookie\");\n const cookies = parseCookies(cookieHeader);\n\n if (cookies.length === 0) {\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 const userSessionHashValue = userSessionHashCookie.value;\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n userSessionHashValue,\n );\n\n return json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n });\n }\n } catch (error) {\n console.error(\"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 const publicKey = typeof process !== \"undefined\" ? process.env.PK_AUTHDOG as string\n : params?.publicKey;\n const publicKeyObj = validateAndParsePublicKey(publicKey);\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 // Try to authenticate using cookies first\n const cookieAuthResult = await authenticateWithCookies(\n request,\n publicKeyObj,\n );\n \n if (cookieAuthResult) {\n // If we have a token in URL, still process it but don't show loading\n if (tokenFromUri) {\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n tokenFromUri,\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 the response with cookies but don't redirect\n // The client-side reload will handle the URL cleanup\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n },\n {\n headers: authResponse.headers,\n }\n );\n }\n }\n return cookieAuthResult;\n }\n\n // If we have a token but no cookie auth, show loading while processing token\n if (tokenFromUri) {\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n tokenFromUri,\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 the response with cookies but don't redirect\n // The client-side reload will handle the URL cleanup\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n },\n {\n headers: authResponse.headers,\n }\n );\n }\n return json({ loading: true });\n }\n\n // If we get here, we're not authenticated and not loading\n return json({\n user: null,\n isAuthenticated: false,\n });\n};\n\nexport {AuthdogProvider} from \"./provider.tsx\"","\"use client\";\nimport React, { useEffect, useState } from \"react\";\n\nexport const AuthdogProvider = ({ children }: { children: React.ReactNode }) => {\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};"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,4BAAAC,EAAA,uBAAAC,EAAA,oBAAAC,IAAA,eAAAC,EAAAN,GAAA,IAAAO,EAAqB,2BAErBC,EAAuE,iCCDvE,IAAAC,EAA2C,iBAgClCC,EAAA,6BA9BIC,EAAkB,CAAC,CAAE,SAAAC,CAAS,IAAqC,CAC9E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,iBAC9BS,GAAc,aACdA,GAAc,cACdU,CACF,EAEA,GAAInB,GAAmB,MAAQA,GAAmB,MAAM,OAAS,IAAK,CAEpE,IAAMM,EAAmB,KAAK,UAAUN,GAAmB,IAAI,EAC/DgB,EAAQ,gBAAgBP,GAAc,aAAa,EAAE,EAAIH,EACzDU,EAAQ,qBAAqBP,GAAc,aAAa,EAAE,EAAIU,EAG9D,IAAME,EAAetB,EACnBC,EACAmB,EACAV,GAAc,cACdN,CACF,EAIA,SAAO,QACL,CACE,KAAMH,EAAkB,KACxB,gBAAiB,EACnB,EACA,CACE,QAASqB,EAAa,OACxB,CACF,CACF,CACA,SAAO,QAAK,CAAE,QAAS,EAAK,CAAC,CAC/B,CAGA,SAAO,QAAK,CACV,KAAM,KACN,gBAAiB,EACnB,CAAC,CACH","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","authenticateWithCookies","publicKeyObj","cookieHeader","cookies","userSessionHashCookie","c","error","remixAuthLoader","context","params","publicKey","tokenFromUri","cookieAuthResult","authResponse"]}
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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C,GAAc,aAC/B,CAAC,EAID,IAAMU,EADM,IAAI,IAAIhB,EAAQ,GAAG,EACN,aAAa,IAAI,OAAO,EAQjD,GANA,QAAQ,IAAI,6BAA8B,CACxC,SAAU,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"]}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{json as u}from"@remix-run/node";import{parseCookies as _,validateAndParsePublicKey as w,fetchUserData as l}from"@authdog/node-commons";import{useEffect as m,useState as f}from"react";import{Fragment as S,jsx as g}from"react/jsx-runtime";var y=({children:n})=>{let[s,i]=f(!0);return m(()=>{if(typeof window<"u"){let a=new URL(window.location.href);if(a.searchParams.get("token")){a.searchParams.delete("token"),window.history.replaceState({},document.title,a.toString()),window.location.reload();return}i(!1)}},[]),s?null:g(S,{children:n})};var p=(n,s,i,a)=>{let e=u({user:n.user,isAuthenticated:!0}),t=new Headers(e.headers),r=JSON.stringify(n?.user),c=s;return t.append("Set-Cookie",`user_session_${i}=${encodeURIComponent(r)}; Path=/; HttpOnly; Secure; SameSite=Strict`),t.append("Set-Cookie",`user_session_hash_${i}=${encodeURIComponent(c)}; Path=/; HttpOnly; Secure; SameSite=Strict`),t.append("Cache-Control","no-store, no-cache, must-revalidate, proxy-revalidate"),t.append("Pragma","no-cache"),t.append("Expires","0"),t.append("Vary","Cookie"),t.append("Content-Type","application/json"),t.append("Access-Control-Allow-Origin","*"),t.append("Access-Control-Allow-Credentials","true"),u({user:n.user,isAuthenticated:!0},{headers:t})},A=async(n,s)=>{try{let i=n.headers.get("Cookie"),a=_(i);if(a.length===0)return u({user:null,isAuthenticated:!1});let e=a.find(t=>t.name===`user_session_hash_${s?.environmentId}`);if(e){let t=e.value,r=await l(s?.identityHost,s?.environmentId,t);return u({user:r.user,isAuthenticated:!0})}}catch(i){console.error("Error authenticating with cookies:",i)}return null},P=async({request:n,context:s,params:i})=>{let a=typeof process<"u"?process.env.PK_AUTHDOG:i?.publicKey,e=w(a),r=new URL(n.url).searchParams.get("token"),c=await A(n,e);if(c){if(r){let o=await l(e?.identityHost,e?.environmentId,r);if(o?.meta&&o?.meta?.code===200){let d=JSON.stringify(o?.user);s[`user_session_${e?.environmentId}`]=d,s[`user_session_hash_${e?.environmentId}`]=r;let h=p(o,r,e?.environmentId,n);return u({user:o.user,isAuthenticated:!0},{headers:h.headers})}}return c}if(r){let o=await l(e?.identityHost,e?.environmentId,r);if(o?.meta&&o?.meta?.code===200){let d=JSON.stringify(o?.user);s[`user_session_${e?.environmentId}`]=d,s[`user_session_hash_${e?.environmentId}`]=r;let h=p(o,r,e?.environmentId,n);return u({user:o.user,isAuthenticated:!0},{headers:h.headers})}return u({loading:!0})}return u({user:null,isAuthenticated:!1})};export{y as AuthdogProvider,A as authenticateWithCookies,p as createAuthResponse,P as remixAuthLoader};
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[o,r]=m(!0);return p(()=>{if(typeof window<"u"){let a=new URL(window.location.href);if(a.searchParams.get("token")){a.searchParams.delete("token"),window.history.replaceState({},document.title,a.toString()),window.location.reload();return}r(!1)}},[]),o?null:k(A,{children:s})};var S=(s,o,r,a)=>{console.log("[Authdog] Creating auth response with:",{hasUser:!!s?.user,environmentId:r,tokenLength:o?.length});let e=c({user:s.user,isAuthenticated:!0}),t=new Headers(e.headers),n=JSON.stringify(s?.user),u=o;console.log("[Authdog] Setting cookies for environment:",r),t.append("Set-Cookie",`user_session_${r}=${encodeURIComponent(n)}; Path=/; HttpOnly; Secure; SameSite=Strict`),t.append("Set-Cookie",`user_session_hash_${r}=${encodeURIComponent(u)}; Path=/; HttpOnly; Secure; SameSite=Strict`),t.append("Cache-Control","no-store, no-cache, must-revalidate, proxy-revalidate"),t.append("Pragma","no-cache"),t.append("Expires","0"),t.append("Vary","Cookie"),t.append("Content-Type","application/json"),t.append("Access-Control-Allow-Origin","*"),t.append("Access-Control-Allow-Credentials","true");let i=process.env.PK_AUTHDOG;if(!i)throw new Error("Public key is not defined");let d=h(i);return c({user:s.user,isAuthenticated:!0,signinUri:`${d.identityHost}/signin/${d.environmentId}`},{headers:t})},v=async(s,o)=>{try{console.log("[Authdog] Attempting cookie authentication for environment:",o?.environmentId);let r=s.headers.get("Cookie"),a=y(r);if(a.length===0)return console.log("[Authdog] No cookies found, returning unauthenticated"),c({user:null,isAuthenticated:!1});let e=a.find(t=>t.name===`user_session_hash_${o?.environmentId}`);if(e){console.log("[Authdog] Found session hash cookie, attempting to fetch user data");let t=e.value,n=await l(o?.identityHost,o?.environmentId,t);return console.log("[Authdog] User data fetch result:",{success:!!n,hasUser:!!n?.user,metaCode:n?.meta?.code}),c({user:n.user,isAuthenticated:!0})}else console.log("[Authdog] No session hash cookie found for environment:",o?.environmentId)}catch(r){console.error("[Authdog] Error authenticating with cookies:",r)}return null},H=async({request:s,context:o,params:r})=>{console.log("[Authdog] Starting authentication loader");let a=typeof process<"u"?process.env.PK_AUTHDOG:r?.publicKey,e=h(a);console.log("[Authdog] Public key parsed:",{hasPublicKey:!!a,environmentId:e?.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 i=await l(e?.identityHost,e?.environmentId,n);if(console.log("[Authdog] Token authentication result:",{success:!!i,hasUser:!!i?.user,metaCode:i?.meta?.code}),i?.meta&&i?.meta?.code===200){let d=JSON.stringify(i?.user);o[`user_session_${e?.environmentId}`]=d,o[`user_session_hash_${e?.environmentId}`]=n;let g=S(i,n,e?.environmentId,s);return c({user:i.user,isAuthenticated:!0,signinUri:`${e.identityHost}/signin/${e.environmentId}`},{headers:g.headers})}}console.log("[Authdog] Attempting cookie authentication");let u=await v(s,e);return u?(console.log("[Authdog] Cookie authentication successful"),u):(console.log("[Authdog] No authentication methods succeeded, returning unauthenticated"),c({user:null,isAuthenticated:!1,signinUri:`${e.identityHost}/signin/${e.environmentId}`}))};export{f as AuthdogProvider,v as authenticateWithCookies,S as createAuthResponse,H as remixAuthLoader};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/provider.tsx"],"sourcesContent":["import { json } from \"@remix-run/node\";\n\nimport { parseCookies, validateAndParsePublicKey, fetchUserData } 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 // 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 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 return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\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 // Get cookies from request\n const cookieHeader = request.headers.get(\"Cookie\");\n const cookies = parseCookies(cookieHeader);\n\n if (cookies.length === 0) {\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 const userSessionHashValue = userSessionHashCookie.value;\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n userSessionHashValue,\n );\n\n return json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n });\n }\n } catch (error) {\n console.error(\"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 const publicKey = typeof process !== \"undefined\" ? process.env.PK_AUTHDOG as string\n : params?.publicKey;\n const publicKeyObj = validateAndParsePublicKey(publicKey);\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 // Try to authenticate using cookies first\n const cookieAuthResult = await authenticateWithCookies(\n request,\n publicKeyObj,\n );\n \n if (cookieAuthResult) {\n // If we have a token in URL, still process it but don't show loading\n if (tokenFromUri) {\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n tokenFromUri,\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 the response with cookies but don't redirect\n // The client-side reload will handle the URL cleanup\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n },\n {\n headers: authResponse.headers,\n }\n );\n }\n }\n return cookieAuthResult;\n }\n\n // If we have a token but no cookie auth, show loading while processing token\n if (tokenFromUri) {\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n tokenFromUri,\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 the response with cookies but don't redirect\n // The client-side reload will handle the URL cleanup\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n },\n {\n headers: authResponse.headers,\n }\n );\n }\n return json({ loading: true });\n }\n\n // If we get here, we're not authenticated and not loading\n return json({\n user: null,\n isAuthenticated: false,\n });\n};\n\nexport {AuthdogProvider} from \"./provider.tsx\"","\"use client\";\nimport React, { useEffect, useState } from \"react\";\n\nexport const AuthdogProvider = ({ children }: { children: React.ReactNode }) => {\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};"],"mappings":"AAAA,OAAS,QAAAA,MAAY,kBAErB,OAAS,gBAAAC,EAAc,6BAAAC,EAA2B,iBAAAC,MAAqB,wBCDvE,OAAgB,aAAAC,EAAW,YAAAC,MAAgB,QAgClC,mBAAAC,EAAA,OAAAC,MAAA,oBA9BF,IAAMC,EAAkB,CAAC,CAAE,SAAAC,CAAS,IAAqC,CAC9E,GAAM,CAACC,EAAWC,CAAY,EAAIN,EAA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Ac,aACdA,GAAc,cACda,CACF,EAEA,GAAIvB,GAAmB,MAAQA,GAAmB,MAAM,OAAS,IAAK,CAEpE,IAAMO,EAAmB,KAAK,UAAUP,GAAmB,IAAI,EAC/DmB,EAAQ,gBAAgBT,GAAc,aAAa,EAAE,EAAIH,EACzDY,EAAQ,qBAAqBT,GAAc,aAAa,EAAE,EAAIa,EAG9D,IAAME,EAAe1B,EACnBC,EACAuB,EACAb,GAAc,cACdP,CACF,EAIA,OAAOE,EACL,CACE,KAAML,EAAkB,KACxB,gBAAiB,EACnB,EACA,CACE,QAASyB,EAAa,OACxB,CACF,CACF,CACA,OAAOpB,EAAK,CAAE,QAAS,EAAK,CAAC,CAC/B,CAGA,OAAOA,EAAK,CACV,KAAM,KACN,gBAAiB,EACnB,CAAC,CACH","names":["json","parseCookies","validateAndParsePublicKey","fetchUserData","useEffect","useState","Fragment","jsx","AuthdogProvider","children","isLoading","setIsLoading","url","createAuthResponse","authenticatedUser","token","environmentId","request","response","json","headers","userSessionValue","userSessionHashValue","authenticateWithCookies","publicKeyObj","cookieHeader","cookies","parseCookies","userSessionHashCookie","c","fetchUserData","error","remixAuthLoader","context","params","publicKey","validateAndParsePublicKey","tokenFromUri","cookieAuthResult","authResponse"]}
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,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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/B,CAAC,EAID,IAAMa,EADM,IAAI,IAAIpB,EAAQ,GAAG,EACN,aAAa,IAAI,OAAO,EAQjD,GANA,QAAQ,IAAI,6BAA8B,CACxC,SAAU,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.6",
3
+ "version": "0.0.8",
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.20"
27
+ "@authdog/node-commons": "0.0.21"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/node": "^22.14.1",