@authdog/remix-node 0.0.12 → 0.1.0

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/client.d.mts CHANGED
@@ -1,9 +1,8 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
1
  import React from 'react';
3
2
 
4
3
  declare const AuthdogProvider: ({ children, }: {
5
4
  children: React.ReactNode;
6
- }) => react_jsx_runtime.JSX.Element;
5
+ }) => React.JSX.Element;
7
6
  declare const ReloadPage: () => null;
8
7
 
9
8
  export { AuthdogProvider, ReloadPage };
package/dist/client.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
1
  import React from 'react';
3
2
 
4
3
  declare const AuthdogProvider: ({ children, }: {
5
4
  children: React.ReactNode;
6
- }) => react_jsx_runtime.JSX.Element;
5
+ }) => React.JSX.Element;
7
6
  declare const ReloadPage: () => null;
8
7
 
9
8
  export { AuthdogProvider, ReloadPage };
package/dist/client.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var d=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var u=(e,t)=>{for(var o in t)d(e,o,{get:t[o],enumerable:!0})},g=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of f(t))!w.call(e,r)&&r!==o&&d(e,r,{get:()=>t[r],enumerable:!(n=l(t,r))||n.enumerable});return e};var h=e=>g(d({},"__esModule",{value:!0}),e);var m={};u(m,{AuthdogProvider:()=>s,ReloadPage:()=>c});module.exports=h(m);var a=require("react"),i=require("react/jsx-runtime"),s=({children:e})=>{let[t,o]=(0,a.useState)(!0);return(0,a.useEffect)(()=>{if(typeof window<"u"){let n=new URL(window.location.href);if(n.searchParams.get("token")){n.searchParams.delete("token"),window.history.replaceState({},document.title,n.toString()),window.location.reload();return}o(!1)}else o(!1)},[]),(0,i.jsx)(i.Fragment,{children:e})},c=()=>((0,a.useEffect)(()=>{if(typeof window<"u"){let e=new URL(window.location.href),t=e.searchParams.get("token");if(t){e.searchParams.delete("token"),window.history.replaceState({},document.title,e.toString()),localStorage.setItem("token",t);return}}},[]),null);
1
+ "use strict";var d=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var u=(e,t)=>{for(var o in t)d(e,o,{get:t[o],enumerable:!0})},h=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of f(t))!w.call(e,r)&&r!==o&&d(e,r,{get:()=>t[r],enumerable:!(n=l(t,r))||n.enumerable});return e};var g=e=>h(d({},"__esModule",{value:!0}),e);var k={};u(k,{AuthdogProvider:()=>s,ReloadPage:()=>c});module.exports=g(k);var a=require("react"),i=require("react/jsx-runtime"),s=({children:e})=>{let[t,o]=(0,a.useState)(!0);return(0,a.useEffect)(()=>{if(typeof window<"u"){let n=new URL(window.location.href);if(n.searchParams.get("token")){n.searchParams.delete("token"),window.history.replaceState({},document.title,n.toString()),window.location.reload();return}o(!1)}else o(!1)},[]),(0,i.jsx)(i.Fragment,{children:e})},c=()=>((0,a.useEffect)(()=>{if(typeof window<"u"){let e=new URL(window.location.href);if(e.searchParams.get("token")){e.searchParams.delete("token"),window.history.replaceState({},document.title,e.toString());return}}},[]),null);
2
2
  //# sourceMappingURL=client.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client.ts","../src/provider.tsx"],"sourcesContent":["// Client-side exports only\nexport { AuthdogProvider, ReloadPage } from \"./provider\"; ","import 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 } else {\n // If we're on the server, don't show loading state\n setIsLoading(false);\n }\n }, []);\n\n // Show children while loading (don't return null)\n return <>{children}</>;\n};\n\nexport const ReloadPage = () => {\n useEffect(() => {\n if (typeof window !== \"undefined\") {\n const url = new URL(window.location.href);\n const token = url.searchParams.get(\"token\");\n if (token) {\n url.searchParams.delete(\"token\");\n window.history.replaceState({}, document.title, url.toString());\n localStorage.setItem(\"token\", token);\n return;\n }\n }\n }, []);\n return null;\n};\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,eAAAC,IAAA,eAAAC,EAAAJ,GCAA,IAAAK,EAA2C,iBAmClCC,EAAA,6BAjCIC,EAAkB,CAAC,CAC9B,SAAAC,CACF,IAEM,CACJ,GAAM,CAACC,EAAWC,CAAY,KAAI,YAAS,EAAI,EAE/C,sBAAU,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,MAEEA,EAAa,EAAK,CAEtB,EAAG,CAAC,CAAC,KAGE,mBAAG,SAAAF,EAAS,CACrB,EAEaI,EAAa,QACxB,aAAU,IAAM,CACd,GAAI,OAAO,OAAW,IAAa,CACjC,IAAMD,EAAM,IAAI,IAAI,OAAO,SAAS,IAAI,EAClCE,EAAQF,EAAI,aAAa,IAAI,OAAO,EAC1C,GAAIE,EAAO,CACTF,EAAI,aAAa,OAAO,OAAO,EAC/B,OAAO,QAAQ,aAAa,CAAC,EAAG,SAAS,MAAOA,EAAI,SAAS,CAAC,EAC9D,aAAa,QAAQ,QAASE,CAAK,EACnC,MACF,CACF,CACF,EAAG,CAAC,CAAC,EACE","names":["client_exports","__export","AuthdogProvider","ReloadPage","__toCommonJS","import_react","import_jsx_runtime","AuthdogProvider","children","isLoading","setIsLoading","url","ReloadPage","token"]}
1
+ {"version":3,"sources":["../src/client.ts","../src/provider.tsx"],"sourcesContent":["// Client-side exports only\nexport { AuthdogProvider, ReloadPage } from \"./provider\";\n","import 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 } else {\n // If we're on the server, don't show loading state\n setIsLoading(false);\n }\n }, []);\n\n // Show children while loading (don't return null)\n return <>{children}</>;\n};\n\nexport const ReloadPage = () => {\n useEffect(() => {\n if (typeof window !== \"undefined\") {\n const url = new URL(window.location.href);\n const token = url.searchParams.get(\"token\");\n if (token) {\n // The server persists the session as HttpOnly cookies; the client\n // must not hold the raw token. Just strip it from the URL.\n url.searchParams.delete(\"token\");\n window.history.replaceState({}, document.title, url.toString());\n return;\n }\n }\n }, []);\n return null;\n};\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,eAAAC,IAAA,eAAAC,EAAAJ,GCAA,IAAAK,EAA2C,iBAmClCC,EAAA,6BAjCIC,EAAkB,CAAC,CAC9B,SAAAC,CACF,IAEM,CACJ,GAAM,CAACC,EAAWC,CAAY,KAAI,YAAS,EAAI,EAE/C,sBAAU,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,MAEEA,EAAa,EAAK,CAEtB,EAAG,CAAC,CAAC,KAGE,mBAAG,SAAAF,EAAS,CACrB,EAEaI,EAAa,QACxB,aAAU,IAAM,CACd,GAAI,OAAO,OAAW,IAAa,CACjC,IAAMD,EAAM,IAAI,IAAI,OAAO,SAAS,IAAI,EAExC,GADcA,EAAI,aAAa,IAAI,OAAO,EAC/B,CAGTA,EAAI,aAAa,OAAO,OAAO,EAC/B,OAAO,QAAQ,aAAa,CAAC,EAAG,SAAS,MAAOA,EAAI,SAAS,CAAC,EAC9D,MACF,CACF,CACF,EAAG,CAAC,CAAC,EACE","names":["client_exports","__export","AuthdogProvider","ReloadPage","__toCommonJS","import_react","import_jsx_runtime","AuthdogProvider","children","isLoading","setIsLoading","url","ReloadPage"]}
package/dist/client.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{useEffect as r,useState as a}from"react";import{Fragment as s,jsx as c}from"react/jsx-runtime";var i=({children:e})=>{let[t,n]=a(!0);return r(()=>{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}n(!1)}else n(!1)},[]),c(s,{children:e})},d=()=>(r(()=>{if(typeof window<"u"){let e=new URL(window.location.href),t=e.searchParams.get("token");if(t){e.searchParams.delete("token"),window.history.replaceState({},document.title,e.toString()),localStorage.setItem("token",t);return}}},[]),null);export{i as AuthdogProvider,d as ReloadPage};
1
+ import{useEffect as n,useState as a}from"react";import{Fragment as s,jsx as c}from"react/jsx-runtime";var i=({children:e})=>{let[r,o]=a(!0);return n(()=>{if(typeof window<"u"){let t=new URL(window.location.href);if(t.searchParams.get("token")){t.searchParams.delete("token"),window.history.replaceState({},document.title,t.toString()),window.location.reload();return}o(!1)}else o(!1)},[]),c(s,{children:e})},d=()=>(n(()=>{if(typeof window<"u"){let e=new URL(window.location.href);if(e.searchParams.get("token")){e.searchParams.delete("token"),window.history.replaceState({},document.title,e.toString());return}}},[]),null);export{i as AuthdogProvider,d as ReloadPage};
2
2
  //# sourceMappingURL=client.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/provider.tsx"],"sourcesContent":["import 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 } else {\n // If we're on the server, don't show loading state\n setIsLoading(false);\n }\n }, []);\n\n // Show children while loading (don't return null)\n return <>{children}</>;\n};\n\nexport const ReloadPage = () => {\n useEffect(() => {\n if (typeof window !== \"undefined\") {\n const url = new URL(window.location.href);\n const token = url.searchParams.get(\"token\");\n if (token) {\n url.searchParams.delete(\"token\");\n window.history.replaceState({}, document.title, url.toString());\n localStorage.setItem(\"token\", token);\n return;\n }\n }\n }, []);\n return null;\n};\n"],"mappings":"AAAA,OAAgB,aAAAA,EAAW,YAAAC,MAAgB,QAmClC,mBAAAC,EAAA,OAAAC,MAAA,oBAjCF,IAAMC,EAAkB,CAAC,CAC9B,SAAAC,CACF,IAEM,CACJ,GAAM,CAACC,EAAWC,CAAY,EAAIN,EAAS,EAAI,EAE/C,OAAAD,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,EACvB,MACF,CAGAD,EAAa,EAAK,CACpB,MAEEA,EAAa,EAAK,CAEtB,EAAG,CAAC,CAAC,EAGEJ,EAAAD,EAAA,CAAG,SAAAG,EAAS,CACrB,EAEaI,EAAa,KACxBT,EAAU,IAAM,CACd,GAAI,OAAO,OAAW,IAAa,CACjC,IAAMQ,EAAM,IAAI,IAAI,OAAO,SAAS,IAAI,EAClCE,EAAQF,EAAI,aAAa,IAAI,OAAO,EAC1C,GAAIE,EAAO,CACTF,EAAI,aAAa,OAAO,OAAO,EAC/B,OAAO,QAAQ,aAAa,CAAC,EAAG,SAAS,MAAOA,EAAI,SAAS,CAAC,EAC9D,aAAa,QAAQ,QAASE,CAAK,EACnC,MACF,CACF,CACF,EAAG,CAAC,CAAC,EACE","names":["useEffect","useState","Fragment","jsx","AuthdogProvider","children","isLoading","setIsLoading","url","ReloadPage","token"]}
1
+ {"version":3,"sources":["../src/provider.tsx"],"sourcesContent":["import 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 } else {\n // If we're on the server, don't show loading state\n setIsLoading(false);\n }\n }, []);\n\n // Show children while loading (don't return null)\n return <>{children}</>;\n};\n\nexport const ReloadPage = () => {\n useEffect(() => {\n if (typeof window !== \"undefined\") {\n const url = new URL(window.location.href);\n const token = url.searchParams.get(\"token\");\n if (token) {\n // The server persists the session as HttpOnly cookies; the client\n // must not hold the raw token. Just strip it from the URL.\n url.searchParams.delete(\"token\");\n window.history.replaceState({}, document.title, url.toString());\n return;\n }\n }\n }, []);\n return null;\n};\n"],"mappings":"AAAA,OAAgB,aAAAA,EAAW,YAAAC,MAAgB,QAmClC,mBAAAC,EAAA,OAAAC,MAAA,oBAjCF,IAAMC,EAAkB,CAAC,CAC9B,SAAAC,CACF,IAEM,CACJ,GAAM,CAACC,EAAWC,CAAY,EAAIN,EAAS,EAAI,EAE/C,OAAAD,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,EACvB,MACF,CAGAD,EAAa,EAAK,CACpB,MAEEA,EAAa,EAAK,CAEtB,EAAG,CAAC,CAAC,EAGEJ,EAAAD,EAAA,CAAG,SAAAG,EAAS,CACrB,EAEaI,EAAa,KACxBT,EAAU,IAAM,CACd,GAAI,OAAO,OAAW,IAAa,CACjC,IAAMQ,EAAM,IAAI,IAAI,OAAO,SAAS,IAAI,EAExC,GADcA,EAAI,aAAa,IAAI,OAAO,EAC/B,CAGTA,EAAI,aAAa,OAAO,OAAO,EAC/B,OAAO,QAAQ,aAAa,CAAC,EAAG,SAAS,MAAOA,EAAI,SAAS,CAAC,EAC9D,MACF,CACF,CACF,EAAG,CAAC,CAAC,EACE","names":["useEffect","useState","Fragment","jsx","AuthdogProvider","children","isLoading","setIsLoading","url","ReloadPage"]}
package/dist/index.d.mts CHANGED
@@ -1,7 +1,6 @@
1
1
  export { AuthdogProvider, ReloadPage } from './client.mjs';
2
2
  import * as _remix_run_node from '@remix-run/node';
3
3
  import { LoaderFunction } from '@remix-run/node';
4
- import 'react/jsx-runtime';
5
4
  import 'react';
6
5
 
7
6
  declare const createAuthResponse: (authenticatedUser: any, token: string, environmentId: string, request: Request) => _remix_run_node.TypedResponse<{
@@ -10,7 +9,7 @@ declare const createAuthResponse: (authenticatedUser: any, token: string, enviro
10
9
  signinUri: string;
11
10
  }>;
12
11
  declare const authenticateWithCookies: (request: Request, publicKeyObj: any) => Promise<_remix_run_node.TypedResponse<{
13
- user: any;
12
+ user: unknown;
14
13
  isAuthenticated: boolean;
15
14
  signinUri: string;
16
15
  }> | null>;
@@ -22,7 +21,7 @@ interface IRemixAuthLoader {
22
21
  };
23
22
  }
24
23
  declare const remixAuthLoader: ({ request, context, params, }: IRemixAuthLoader) => Promise<_remix_run_node.TypedResponse<{
25
- user: any;
24
+ user: unknown;
26
25
  isAuthenticated: boolean;
27
26
  signinUri: string;
28
27
  }>>;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  export { AuthdogProvider, ReloadPage } from './client.js';
2
2
  import * as _remix_run_node from '@remix-run/node';
3
3
  import { LoaderFunction } from '@remix-run/node';
4
- import 'react/jsx-runtime';
5
4
  import 'react';
6
5
 
7
6
  declare const createAuthResponse: (authenticatedUser: any, token: string, environmentId: string, request: Request) => _remix_run_node.TypedResponse<{
@@ -10,7 +9,7 @@ declare const createAuthResponse: (authenticatedUser: any, token: string, enviro
10
9
  signinUri: string;
11
10
  }>;
12
11
  declare const authenticateWithCookies: (request: Request, publicKeyObj: any) => Promise<_remix_run_node.TypedResponse<{
13
- user: any;
12
+ user: unknown;
14
13
  isAuthenticated: boolean;
15
14
  signinUri: string;
16
15
  }> | null>;
@@ -22,7 +21,7 @@ interface IRemixAuthLoader {
22
21
  };
23
22
  }
24
23
  declare const remixAuthLoader: ({ request, context, params, }: IRemixAuthLoader) => Promise<_remix_run_node.TypedResponse<{
25
- user: any;
24
+ user: unknown;
26
25
  isAuthenticated: boolean;
27
26
  signinUri: string;
28
27
  }>>;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var m=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var $=(t,e)=>{for(var n in e)m(t,n,{get:e[n],enumerable:!0})},I=(t,e,n,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of H(e))!R.call(t,o)&&o!==n&&m(t,o,{get:()=>e[o],enumerable:!(s=C(e,o))||s.enumerable});return t};var L=t=>I(m({},"__esModule",{value:!0}),t);var U={};$(U,{AuthdogProvider:()=>S,ReloadPage:()=>k,authenticateWithCookies:()=>A,createAuthResponse:()=>f,identityDevAction:()=>P,identityLoader:()=>_,logoutLoader:()=>w,remixAuthLoader:()=>p});module.exports=L(U);var d=require("react"),g=require("react/jsx-runtime"),S=({children:t})=>{let[e,n]=(0,d.useState)(!0);return(0,d.useEffect)(()=>{if(typeof window<"u"){let s=new URL(window.location.href);if(s.searchParams.get("token")){s.searchParams.delete("token"),window.history.replaceState({},document.title,s.toString()),window.location.reload();return}n(!1)}else n(!1)},[]),(0,g.jsx)(g.Fragment,{children:t})},k=()=>((0,d.useEffect)(()=>{if(typeof window<"u"){let t=new URL(window.location.href),e=t.searchParams.get("token");if(e){t.searchParams.delete("token"),window.history.replaceState({},document.title,t.toString()),localStorage.setItem("token",e);return}}},[]),null);var u=require("@remix-run/node"),c=require("@authdog/node-commons"),f=(t,e,n,s)=>{console.log("[Authdog] Creating auth response with:",{hasUser:!!t?.user,environmentId:n,tokenLength:e?.length});let o=(0,u.json)({user:t.user,isAuthenticated:!0}),r=new Headers(o.headers),i=JSON.stringify(t?.user),h=e;console.log("[Authdog] Setting cookies for environment:",n),r.append("Set-Cookie",`user_session_${n}=${encodeURIComponent(i)}; Path=/; HttpOnly; Secure; SameSite=Strict`),r.append("Set-Cookie",`user_session_hash_${n}=${encodeURIComponent(h)}; 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");let a=process.env.PK_AUTHDOG;if(!a)throw new Error("Public key is not defined");let l=(0,c.validateAndParsePublicKey)(a);return(0,u.json)({user:t.user,isAuthenticated:!0,signinUri:`${l.identityHost}/signin/${l.environmentId}`},{headers:r})},A=async(t,e)=>{try{console.log("[Authdog] Attempting cookie authentication for environment:",e?.environmentId);let n=t.headers.get("Cookie"),s=(0,c.parseCookies)(n);if(s.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 o=s.find(r=>r.name===`user_session_hash_${e?.environmentId}`);if(o){console.log("[Authdog] Found session hash cookie, attempting to fetch user data");let r=o.value,i=await(0,c.fetchUserData)(e?.identityHost,e?.environmentId,r);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,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},p=async({request:t,context:e,params:n})=>{console.log("[Authdog] Starting authentication loader");let s=n?.publicKey;if(!s)throw Error("[Authdog][Remix] Missing public key");let o=(0,c.validateAndParsePublicKey)(s);console.log("[Authdog] Public key parsed:",{hasPublicKey:!!s,environmentId:o?.environmentId});let i=new URL(t.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)(o?.identityHost,o?.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 l=JSON.stringify(a?.user);e[`user_session_${o?.environmentId}`]=l,e[`user_session_hash_${o?.environmentId}`]=i;let x=f(a,i,o?.environmentId,t);return(0,u.json)({user:a.user,isAuthenticated:!0,signinUri:`${o.identityHost}/signin/${o.environmentId}`},{headers:x.headers})}}console.log("[Authdog] Attempting cookie authentication");let h=await A(t,o);return h?(console.log("[Authdog] Cookie authentication successful"),h):(console.log("[Authdog] No authentication methods succeeded, returning unauthenticated"),(0,u.json)({user:null,isAuthenticated:!1,signinUri:`${o.identityHost}/signin/${o.environmentId}`}))};var y=require("@remix-run/node"),w=async({context:t,request:e})=>{let n=new Headers,s=process.env.PK_AUTHDOG;if(!s)throw new Error("Public key is not defined");let r=JSON.parse(Buffer.from(s.replace("pk_",""),"base64").toString("utf-8")).environmentId;return n.append("Set-Cookie",`user_session_${r}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Strict`),n.append("Set-Cookie",`user_session_hash_${r}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Strict`),(0,y.redirect)("/",{headers:n})};var v=require("@remix-run/node");var _=()=>async({context:t,request:e})=>await p({request:e,context:t,params:{publicKey:process.env.PK_AUTHDOG}}),P=async({redirectTo:t="/"})=>{let e=process.env.PK_AUTHDOG;if(!e)throw new Error("Public key is not defined");let s=JSON.parse(Buffer.from(e.replace("pk_",""),"base64").toString("utf-8")).environmentId,o=`user_session_${s}`,r=`user_session_hash_${s}`,i=(0,v.redirect)(t);return i.headers.append("Set-Cookie",`${o}=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=0`),i.headers.append("Set-Cookie",`${r}=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=0`),i};
1
+ "use strict";var f=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var L=(o,t)=>{for(var n in t)f(o,n,{get:t[n],enumerable:!0})},E=(o,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of I(t))!C.call(o,e)&&e!==n&&f(o,e,{get:()=>t[e],enumerable:!(i=$(t,e))||i.enumerable});return o};var K=o=>E(f({},"__esModule",{value:!0}),o);var N={};L(N,{AuthdogProvider:()=>k,ReloadPage:()=>S,authenticateWithCookies:()=>A,createAuthResponse:()=>y,identityDevAction:()=>H,identityLoader:()=>x,logoutLoader:()=>P,remixAuthLoader:()=>g});module.exports=K(N);var l=require("react"),p=require("react/jsx-runtime"),k=({children:o})=>{let[t,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)}else n(!1)},[]),(0,p.jsx)(p.Fragment,{children:o})},S=()=>((0,l.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());return}}},[]),null);var h=require("@remix-run/node"),c=require("@authdog/node-commons"),r=!1,y=(o,t,n,i)=>{r&&console.log("[Authdog] Creating auth response with:",{hasUser:!!o?.user,environmentId:n});let e=new Headers,u=JSON.stringify(o?.user),s=t;r&&console.log("[Authdog] Setting cookies for environment:",n),e.append("Set-Cookie",`user_session_${n}=${encodeURIComponent(u)}; Path=/; HttpOnly; Secure; SameSite=Strict`),e.append("Set-Cookie",`user_session_hash_${n}=${encodeURIComponent(s)}; Path=/; HttpOnly; Secure; SameSite=Strict`),e.append("Cache-Control","no-store, no-cache, must-revalidate, proxy-revalidate"),e.append("Pragma","no-cache"),e.append("Expires","0"),e.append("Vary","Cookie"),e.append("Content-Type","application/json");let a=process.env.PK_AUTHDOG;if(!a)throw new Error("Public key is not defined");let d=(0,c.validateAndParsePublicKey)(a);return(0,h.json)({user:o.user,isAuthenticated:!0,signinUri:`${d.identityHost}/signin/${d.environmentId}`},{headers:e})},A=async(o,t)=>{try{r&&console.log("[Authdog] Attempting cookie authentication for environment:",t?.environmentId);let n=o.headers.get("Cookie"),i=(0,c.parseCookies)(n),e=(0,h.json)({user:null,isAuthenticated:!1,signinUri:`${t.identityHost}/signin/${t.environmentId}`});if(i.length===0)return r&&console.log("[Authdog] No cookies found, returning unauthenticated"),e;let u=i.find(s=>s.name===`user_session_hash_${t?.environmentId}`);if(u){r&&console.log("[Authdog] Found session hash cookie, attempting to fetch user data");let s=u.value,a=await(0,c.fetchUserData)(t?.identityHost,t?.environmentId,s);return r&&console.log("[Authdog] User data fetch result:",{success:!!a,hasUser:!!a?.user,metaCode:a?.meta?.code}),(0,c.isAuthenticatedUserInfo)(a)?(0,h.json)({user:a.user,isAuthenticated:!0,signinUri:`${t.identityHost}/signin/${t.environmentId}`}):e}else r&&console.log("[Authdog] No session hash cookie found for environment:",t?.environmentId)}catch(n){console.error("[Authdog] Error authenticating with cookies:",n)}return null},g=async({request:o,context:t,params:n})=>{r&&console.log("[Authdog] Starting authentication loader");let i=n?.publicKey;if(!i)throw Error("[Authdog][Remix] Missing public key");let e=(0,c.validateAndParsePublicKey)(i);r&&console.log("[Authdog] Public key parsed:",{hasPublicKey:!!i,environmentId:e?.environmentId});let s=new URL(o.url).searchParams.get("token");if(r&&console.log("[Authdog] URL token check:",{hasToken:!!s}),s){r&&console.log("[Authdog] Processing token from URL");let d=await(0,c.fetchUserData)(e?.identityHost,e?.environmentId,s);if(r&&console.log("[Authdog] Token authentication result:",{success:!!d,hasUser:!!d?.user,metaCode:d?.meta?.code}),(0,c.isAuthenticatedUserInfo)(d)){let R=JSON.stringify(d?.user);t[`user_session_${e?.environmentId}`]=R,t[`user_session_hash_${e?.environmentId}`]=s;let U=y(d,s,e?.environmentId,o);return(0,h.json)({user:d.user,isAuthenticated:!0,signinUri:`${e.identityHost}/signin/${e.environmentId}`},{headers:U.headers})}}r&&console.log("[Authdog] Attempting cookie authentication");let a=await A(o,e);return a?(r&&console.log("[Authdog] Cookie authentication successful"),a):(r&&console.log("[Authdog] No authentication methods succeeded, returning unauthenticated"),(0,h.json)({user:null,isAuthenticated:!1,signinUri:`${e.identityHost}/signin/${e.environmentId}`}))};var v=require("@remix-run/node"),w=require("@authdog/node-commons"),P=async({context:o,request:t})=>{let n=new Headers,i=process.env.PK_AUTHDOG;if(!i)throw new Error("Public key is not defined");let u=(0,w.validateAndParsePublicKey)(i).environmentId;return n.append("Set-Cookie",`user_session_${u}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Strict`),n.append("Set-Cookie",`user_session_hash_${u}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Strict`),(0,v.redirect)("/",{headers:n})};var _=require("@remix-run/node"),m=require("@authdog/node-commons");var x=()=>async({context:o,request:t})=>await g({request:t,context:o,params:{publicKey:process.env.PK_AUTHDOG}}),H=async({redirectTo:o="/"})=>{throw new Error("identityDevAction is not available in production")};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/provider.tsx","../src/authLoader.ts","../src/logout.ts","../src/utils.ts"],"sourcesContent":["export { AuthdogProvider, ReloadPage } from \"./provider\";\n\nexport {\n createAuthResponse,\n authenticateWithCookies,\n remixAuthLoader\n} from \"./authLoader\";\n\nexport {logoutLoader} from \"./logout\";\n\nexport {\n identityLoader,\n identityDevAction \n} from \"./utils\";","import 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 } else {\n // If we're on the server, don't show loading state\n setIsLoading(false);\n }\n }, []);\n\n // Show children while loading (don't return null)\n return <>{children}</>;\n};\n\nexport const ReloadPage = () => {\n useEffect(() => {\n if (typeof window !== \"undefined\") {\n const url = new URL(window.location.href);\n const token = url.searchParams.get(\"token\");\n if (token) {\n url.searchParams.delete(\"token\");\n window.history.replaceState({}, document.title, url.toString());\n localStorage.setItem(\"token\", token);\n return;\n }\n }\n }, []);\n return null;\n};\n","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 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\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 = 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 };","import { LoaderFunction, redirect } from \"@remix-run/node\";\n\nexport const logoutLoader: LoaderFunction = async ({ context, request }) => {\n const headers = new Headers();\n \n const publicKey = process.env.PK_AUTHDOG;\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n\n const payload = JSON.parse(\n Buffer.from(publicKey.replace(\"pk_\", \"\"), \"base64\").toString(\"utf-8\")\n );\n\n const environmentId = payload.environmentId;\n\n headers.append(\"Set-Cookie\", `user_session_${environmentId}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Strict`);\n headers.append(\"Set-Cookie\", `user_session_hash_${environmentId}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Strict`);\n\n return redirect(\"/\", { headers });\n};","import { LoaderFunction, redirect } from \"@remix-run/node\";\nimport { remixAuthLoader } from \"./authLoader\";\n\nexport const identityLoader = (): LoaderFunction => {\n return async ({ context, request }) => {\n return await remixAuthLoader({\n request,\n context,\n params: {\n publicKey: process.env.PK_AUTHDOG,\n },\n });\n };\n};\n\nexport const identityDevAction = async ({\n redirectTo = \"/\",\n}: {\n redirectTo: string;\n}) => {\n const publicKey = process.env.PK_AUTHDOG as string;\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n \n const payload = JSON.parse(\n Buffer.from(publicKey.replace(\"pk_\", \"\"), \"base64\").toString(\"utf-8\"),\n );\n \n const environmentId = payload.environmentId;\n const cookieNameSession = `user_session_${environmentId}`;\n const cookieNameHash = `user_session_hash_${environmentId}`;\n \n const response = redirect(redirectTo);\n \n response.headers.append(\n \"Set-Cookie\",\n `${cookieNameSession}=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=0`\n );\n response.headers.append(\n \"Set-Cookie\",\n `${cookieNameHash}=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=0`\n );\n \n return response;\n };"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,eAAAC,EAAA,4BAAAC,EAAA,uBAAAC,EAAA,sBAAAC,EAAA,mBAAAC,EAAA,iBAAAC,EAAA,oBAAAC,IAAA,eAAAC,EAAAV,GCAA,IAAAW,EAA2C,iBAmClCC,EAAA,6BAjCIC,EAAkB,CAAC,CAC9B,SAAAC,CACF,IAEM,CACJ,GAAM,CAACC,EAAWC,CAAY,KAAI,YAAS,EAAI,EAE/C,sBAAU,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,MAEEA,EAAa,EAAK,CAEtB,EAAG,CAAC,CAAC,KAGE,mBAAG,SAAAF,EAAS,CACrB,EAEaI,EAAa,QACxB,aAAU,IAAM,CACd,GAAI,OAAO,OAAW,IAAa,CACjC,IAAMD,EAAM,IAAI,IAAI,OAAO,SAAS,IAAI,EAClCE,EAAQF,EAAI,aAAa,IAAI,OAAO,EAC1C,GAAIE,EAAO,CACTF,EAAI,aAAa,OAAO,OAAO,EAC/B,OAAO,QAAQ,aAAa,CAAC,EAAG,SAAS,MAAOA,EAAI,SAAS,CAAC,EAC9D,aAAa,QAAQ,QAASE,CAAK,EACnC,MACF,CACF,CACF,EAAG,CAAC,CAAC,EACE,MCnDT,IAAAC,EAAqB,2BAErBC,EAIO,iCAGMC,EAAqB,CAChCC,EACAC,EACAC,EAC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GlC,IAAMC,EAAiB,IACrB,MAAO,CAAE,QAAAC,EAAS,QAAAC,CAAQ,IACxB,MAAMC,EAAgB,CAC3B,QAAAD,EACA,QAAAD,EACA,OAAQ,CACN,UAAW,QAAQ,IAAI,UACzB,CACF,CAAC,EAIQG,EAAoB,MAAO,CACpC,WAAAC,EAAa,GACjB,IAEM,CACF,IAAMC,EAAY,QAAQ,IAAI,WAC9B,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,2BAA2B,EAO7C,IAAMC,EAJU,KAAK,MACnB,OAAO,KAAKD,EAAU,QAAQ,MAAO,EAAE,EAAG,QAAQ,EAAE,SAAS,OAAO,CACtE,EAE8B,cACxBE,EAAoB,gBAAgBD,CAAa,GACjDE,EAAiB,qBAAqBF,CAAa,GAEnDG,KAAW,YAASL,CAAU,EAEpC,OAAAK,EAAS,QAAQ,OACf,aACA,GAAGF,CAAiB,yDACtB,EACAE,EAAS,QAAQ,OACf,aACA,GAAGD,CAAc,yDACnB,EAEOC,CACT","names":["index_exports","__export","AuthdogProvider","ReloadPage","authenticateWithCookies","createAuthResponse","identityDevAction","identityLoader","logoutLoader","remixAuthLoader","__toCommonJS","import_react","import_jsx_runtime","AuthdogProvider","children","isLoading","setIsLoading","url","ReloadPage","token","import_node","import_node_commons","createAuthResponse","authenticatedUser","token","environmentId","request","response","headers","userSessionValue","userSessionHashValue","publicKey","publicKeyObj","authenticateWithCookies","cookieHeader","cookies","userSessionHashCookie","c","error","remixAuthLoader","context","params","tokenFromUri","authResponse","cookieAuthResult","import_node","logoutLoader","context","request","headers","publicKey","environmentId","import_node","identityLoader","context","request","remixAuthLoader","identityDevAction","redirectTo","publicKey","environmentId","cookieNameSession","cookieNameHash","response"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/provider.tsx","../src/authLoader.ts","../src/logout.ts","../src/utils.ts"],"sourcesContent":["export { AuthdogProvider, ReloadPage } from \"./provider\";\n\nexport {\n createAuthResponse,\n authenticateWithCookies,\n remixAuthLoader,\n} from \"./authLoader\";\n\nexport { logoutLoader } from \"./logout\";\n\nexport { identityLoader, identityDevAction } from \"./utils\";\n","import 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 } else {\n // If we're on the server, don't show loading state\n setIsLoading(false);\n }\n }, []);\n\n // Show children while loading (don't return null)\n return <>{children}</>;\n};\n\nexport const ReloadPage = () => {\n useEffect(() => {\n if (typeof window !== \"undefined\") {\n const url = new URL(window.location.href);\n const token = url.searchParams.get(\"token\");\n if (token) {\n // The server persists the session as HttpOnly cookies; the client\n // must not hold the raw token. Just strip it from the URL.\n url.searchParams.delete(\"token\");\n window.history.replaceState({}, document.title, url.toString());\n return;\n }\n }\n }, []);\n return null;\n};\n","import { json } from \"@remix-run/node\";\n\nimport {\n parseCookies,\n validateAndParsePublicKey,\n fetchUserData,\n isAuthenticatedUserInfo,\n} from \"@authdog/node-commons\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\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 if (isDev) {\n console.log(\"[Authdog] Creating auth response with:\", {\n hasUser: !!authenticatedUser?.user,\n environmentId,\n });\n }\n\n // Set cookies in the response headers\n const headers = new Headers();\n\n // Serialize the user object separately\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n const userSessionHashValue = token;\n\n if (isDev) {\n console.log(\"[Authdog] Setting cookies for environment:\", environmentId);\n }\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\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 if (isDev) {\n console.log(\n \"[Authdog] Attempting cookie authentication for environment:\",\n publicKeyObj?.environmentId,\n );\n }\n\n // Get cookies from request (parseCookies URL-decodes values)\n const cookieHeader = request.headers.get(\"Cookie\");\n const cookies = parseCookies(cookieHeader);\n\n const unauthenticated = json({\n user: null,\n isAuthenticated: false,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`,\n });\n\n if (cookies.length === 0) {\n if (isDev) {\n console.log(\"[Authdog] No cookies found, returning unauthenticated\");\n }\n return unauthenticated;\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 if (isDev) {\n console.log(\n \"[Authdog] Found session hash cookie, attempting to fetch user data\",\n );\n }\n const userSessionHashValue = userSessionHashCookie.value;\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n userSessionHashValue,\n );\n\n if (isDev) {\n console.log(\"[Authdog] User data fetch result:\", {\n success: !!authenticatedUser,\n hasUser: !!authenticatedUser?.user,\n metaCode: authenticatedUser?.meta?.code,\n });\n }\n\n if (!isAuthenticatedUserInfo(authenticatedUser)) {\n return unauthenticated;\n }\n\n return json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`,\n });\n } else if (isDev) {\n console.log(\n \"[Authdog] No session hash cookie found for environment:\",\n publicKeyObj?.environmentId,\n );\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 if (isDev) {\n console.log(\"[Authdog] Starting authentication loader\");\n }\n\n const publicKey = 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 if (isDev) {\n console.log(\"[Authdog] Public key parsed:\", {\n hasPublicKey: !!publicKey,\n environmentId: publicKeyObj?.environmentId,\n });\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 if (isDev) {\n console.log(\"[Authdog] URL token check:\", {\n hasToken: !!tokenFromUri,\n });\n }\n\n // If we have a token in URL, process it first\n if (tokenFromUri) {\n if (isDev) {\n console.log(\"[Authdog] Processing token from URL\");\n }\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n tokenFromUri,\n );\n\n if (isDev) {\n console.log(\"[Authdog] Token authentication result:\", {\n success: !!authenticatedUser,\n hasUser: !!authenticatedUser?.user,\n metaCode: authenticatedUser?.meta?.code,\n });\n }\n\n if (isAuthenticatedUserInfo(authenticatedUser)) {\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}`] =\n 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 if (isDev) {\n console.log(\"[Authdog] Attempting cookie authentication\");\n }\n const cookieAuthResult = await authenticateWithCookies(request, publicKeyObj);\n if (cookieAuthResult) {\n if (isDev) {\n console.log(\"[Authdog] Cookie authentication successful\");\n }\n return cookieAuthResult;\n }\n\n if (isDev) {\n console.log(\n \"[Authdog] No authentication methods succeeded, returning unauthenticated\",\n );\n }\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","import { LoaderFunction, redirect } from \"@remix-run/node\";\nimport { validateAndParsePublicKey } from \"@authdog/node-commons\";\n\nexport const logoutLoader: LoaderFunction = async ({ context, request }) => {\n const headers = new Headers();\n\n const publicKey = process.env.PK_AUTHDOG;\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n\n const publicKeyObj = validateAndParsePublicKey(publicKey);\n\n const environmentId = publicKeyObj.environmentId;\n\n headers.append(\n \"Set-Cookie\",\n `user_session_${environmentId}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Strict`,\n );\n headers.append(\n \"Set-Cookie\",\n `user_session_hash_${environmentId}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Strict`,\n );\n\n return redirect(\"/\", { headers });\n};\n","import { LoaderFunction, redirect } from \"@remix-run/node\";\nimport {\n validateAndParsePublicKey,\n sanitizeRedirectPath,\n} from \"@authdog/node-commons\";\nimport { remixAuthLoader } from \"./authLoader\";\n\nexport const identityLoader = (): LoaderFunction => {\n return async ({ context, request }) => {\n return await remixAuthLoader({\n request,\n context,\n params: {\n publicKey: process.env.PK_AUTHDOG,\n },\n });\n };\n};\n\nexport const identityDevAction = async ({\n redirectTo = \"/\",\n}: {\n redirectTo: string;\n}) => {\n if (process.env.NODE_ENV === \"production\") {\n throw new Error(\"identityDevAction is not available in production\");\n }\n\n const publicKey = process.env.PK_AUTHDOG as string;\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n\n const publicKeyObj = validateAndParsePublicKey(publicKey);\n\n const environmentId = publicKeyObj.environmentId;\n const cookieNameSession = `user_session_${environmentId}`;\n const cookieNameHash = `user_session_hash_${environmentId}`;\n\n const response = redirect(sanitizeRedirectPath(redirectTo));\n\n response.headers.append(\n \"Set-Cookie\",\n `${cookieNameSession}=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=0`,\n );\n response.headers.append(\n \"Set-Cookie\",\n `${cookieNameHash}=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=0`,\n );\n\n return response;\n};\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,eAAAC,EAAA,4BAAAC,EAAA,uBAAAC,EAAA,sBAAAC,EAAA,mBAAAC,EAAA,iBAAAC,EAAA,oBAAAC,IAAA,eAAAC,EAAAV,GCAA,IAAAW,EAA2C,iBAmClCC,EAAA,6BAjCIC,EAAkB,CAAC,CAC9B,SAAAC,CACF,IAEM,CACJ,GAAM,CAACC,EAAWC,CAAY,KAAI,YAAS,EAAI,EAE/C,sBAAU,IAAM,CAEd,GAAI,OAAO,OAAW,IAAa,CAEjC,IAAMC,EAAM,IAAI,IAAI,OAAO,SAAS,IAAI,EAGxC,GAFcA,EAAI,aAAa,IAAI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AM,KACN,gBAAiB,GACjB,UAAW,GAAGU,EAAa,YAAY,WAAWA,EAAa,aAAa,EAC9E,CAAC,EACH,EC1QA,IAAAc,EAAyC,2BACzCC,EAA0C,iCAE7BC,EAA+B,MAAO,CAAE,QAAAC,EAAS,QAAAC,CAAQ,IAAM,CAC1E,IAAMC,EAAU,IAAI,QAEdC,EAAY,QAAQ,IAAI,WAC9B,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,2BAA2B,EAK7C,IAAMC,KAFe,6BAA0BD,CAAS,EAErB,cAEnC,OAAAD,EAAQ,OACN,aACA,gBAAgBE,CAAa,yDAC/B,EACAF,EAAQ,OACN,aACA,qBAAqBE,CAAa,yDACpC,KAEO,YAAS,IAAK,CAAE,QAAAF,CAAQ,CAAC,CAClC,ECzBA,IAAAG,EAAyC,2BACzCC,EAGO,iCAGA,IAAMC,EAAiB,IACrB,MAAO,CAAE,QAAAC,EAAS,QAAAC,CAAQ,IACxB,MAAMC,EAAgB,CAC3B,QAAAD,EACA,QAAAD,EACA,OAAQ,CACN,UAAW,QAAQ,IAAI,UACzB,CACF,CAAC,EAIQG,EAAoB,MAAO,CACtC,WAAAC,EAAa,GACf,IAEM,CAEF,MAAM,IAAI,MAAM,kDAAkD,CA0BtE","names":["index_exports","__export","AuthdogProvider","ReloadPage","authenticateWithCookies","createAuthResponse","identityDevAction","identityLoader","logoutLoader","remixAuthLoader","__toCommonJS","import_react","import_jsx_runtime","AuthdogProvider","children","isLoading","setIsLoading","url","ReloadPage","import_node","import_node_commons","isDev","createAuthResponse","authenticatedUser","token","environmentId","request","headers","userSessionValue","userSessionHashValue","publicKey","publicKeyObj","authenticateWithCookies","cookieHeader","cookies","unauthenticated","userSessionHashCookie","c","error","remixAuthLoader","context","params","tokenFromUri","authResponse","cookieAuthResult","import_node","import_node_commons","logoutLoader","context","request","headers","publicKey","environmentId","import_node","import_node_commons","identityLoader","context","request","remixAuthLoader","identityDevAction","redirectTo"]}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import{useEffect as l,useState as S}from"react";import{Fragment as w,jsx as v}from"react/jsx-runtime";var k=({children:t})=>{let[e,s]=S(!0);return l(()=>{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}s(!1)}else s(!1)},[]),v(w,{children:t})},y=()=>(l(()=>{if(typeof window<"u"){let t=new URL(window.location.href),e=t.searchParams.get("token");if(e){t.searchParams.delete("token"),window.history.replaceState({},document.title,t.toString()),localStorage.setItem("token",e);return}}},[]),null);import{json as c}from"@remix-run/node";import{parseCookies as _,validateAndParsePublicKey as g,fetchUserData as p}from"@authdog/node-commons";var m=(t,e,s,r)=>{console.log("[Authdog] Creating auth response with:",{hasUser:!!t?.user,environmentId:s,tokenLength:e?.length});let o=c({user:t.user,isAuthenticated:!0}),n=new Headers(o.headers),i=JSON.stringify(t?.user),u=e;console.log("[Authdog] Setting cookies for environment:",s),n.append("Set-Cookie",`user_session_${s}=${encodeURIComponent(i)}; Path=/; HttpOnly; Secure; SameSite=Strict`),n.append("Set-Cookie",`user_session_hash_${s}=${encodeURIComponent(u)}; Path=/; HttpOnly; Secure; SameSite=Strict`),n.append("Cache-Control","no-store, no-cache, must-revalidate, proxy-revalidate"),n.append("Pragma","no-cache"),n.append("Expires","0"),n.append("Vary","Cookie"),n.append("Content-Type","application/json"),n.append("Access-Control-Allow-Origin","*"),n.append("Access-Control-Allow-Credentials","true");let a=process.env.PK_AUTHDOG;if(!a)throw new Error("Public key is not defined");let d=g(a);return c({user:t.user,isAuthenticated:!0,signinUri:`${d.identityHost}/signin/${d.environmentId}`},{headers:n})},f=async(t,e)=>{try{console.log("[Authdog] Attempting cookie authentication for environment:",e?.environmentId);let s=t.headers.get("Cookie"),r=_(s);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 o=r.find(n=>n.name===`user_session_hash_${e?.environmentId}`);if(o){console.log("[Authdog] Found session hash cookie, attempting to fetch user data");let n=o.value,i=await p(e?.identityHost,e?.environmentId,n);return console.log("[Authdog] User data fetch result:",{success:!!i,hasUser:!!i?.user,metaCode:i?.meta?.code}),c({user:i.user,isAuthenticated:!0,signinUri:`${e.identityHost}/signin/${e.environmentId}`})}else console.log("[Authdog] No session hash cookie found for environment:",e?.environmentId)}catch(s){console.error("[Authdog] Error authenticating with cookies:",s)}return null},h=async({request:t,context:e,params:s})=>{console.log("[Authdog] Starting authentication loader");let r=s?.publicKey;if(!r)throw Error("[Authdog][Remix] Missing public key");let o=g(r);console.log("[Authdog] Public key parsed:",{hasPublicKey:!!r,environmentId:o?.environmentId});let i=new URL(t.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 p(o?.identityHost,o?.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 d=JSON.stringify(a?.user);e[`user_session_${o?.environmentId}`]=d,e[`user_session_hash_${o?.environmentId}`]=i;let A=m(a,i,o?.environmentId,t);return c({user:a.user,isAuthenticated:!0,signinUri:`${o.identityHost}/signin/${o.environmentId}`},{headers:A.headers})}}console.log("[Authdog] Attempting cookie authentication");let u=await f(t,o);return u?(console.log("[Authdog] Cookie authentication successful"),u):(console.log("[Authdog] No authentication methods succeeded, returning unauthenticated"),c({user:null,isAuthenticated:!1,signinUri:`${o.identityHost}/signin/${o.environmentId}`}))};import{redirect as P}from"@remix-run/node";var x=async({context:t,request:e})=>{let s=new Headers,r=process.env.PK_AUTHDOG;if(!r)throw new Error("Public key is not defined");let n=JSON.parse(Buffer.from(r.replace("pk_",""),"base64").toString("utf-8")).environmentId;return s.append("Set-Cookie",`user_session_${n}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Strict`),s.append("Set-Cookie",`user_session_hash_${n}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Strict`),P("/",{headers:s})};import{redirect as C}from"@remix-run/node";var H=()=>async({context:t,request:e})=>await h({request:e,context:t,params:{publicKey:process.env.PK_AUTHDOG}}),R=async({redirectTo:t="/"})=>{let e=process.env.PK_AUTHDOG;if(!e)throw new Error("Public key is not defined");let r=JSON.parse(Buffer.from(e.replace("pk_",""),"base64").toString("utf-8")).environmentId,o=`user_session_${r}`,n=`user_session_hash_${r}`,i=C(t);return i.headers.append("Set-Cookie",`${o}=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=0`),i.headers.append("Set-Cookie",`${n}=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=0`),i};export{k as AuthdogProvider,y as ReloadPage,f as authenticateWithCookies,m as createAuthResponse,R as identityDevAction,H as identityLoader,x as logoutLoader,h as remixAuthLoader};
1
+ import{useEffect as l,useState as S}from"react";import{Fragment as P,jsx as _}from"react/jsx-runtime";var v=({children:o})=>{let[t,n]=S(!0);return l(()=>{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)}else n(!1)},[]),_(P,{children:o})},w=()=>(l(()=>{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());return}}},[]),null);import{json as d}from"@remix-run/node";import{parseCookies as x,validateAndParsePublicKey as p,fetchUserData as g,isAuthenticatedUserInfo as m}from"@authdog/node-commons";var r=!1,f=(o,t,n,i)=>{r&&console.log("[Authdog] Creating auth response with:",{hasUser:!!o?.user,environmentId:n});let e=new Headers,c=JSON.stringify(o?.user),s=t;r&&console.log("[Authdog] Setting cookies for environment:",n),e.append("Set-Cookie",`user_session_${n}=${encodeURIComponent(c)}; Path=/; HttpOnly; Secure; SameSite=Strict`),e.append("Set-Cookie",`user_session_hash_${n}=${encodeURIComponent(s)}; Path=/; HttpOnly; Secure; SameSite=Strict`),e.append("Cache-Control","no-store, no-cache, must-revalidate, proxy-revalidate"),e.append("Pragma","no-cache"),e.append("Expires","0"),e.append("Vary","Cookie"),e.append("Content-Type","application/json");let a=process.env.PK_AUTHDOG;if(!a)throw new Error("Public key is not defined");let u=p(a);return d({user:o.user,isAuthenticated:!0,signinUri:`${u.identityHost}/signin/${u.environmentId}`},{headers:e})},y=async(o,t)=>{try{r&&console.log("[Authdog] Attempting cookie authentication for environment:",t?.environmentId);let n=o.headers.get("Cookie"),i=x(n),e=d({user:null,isAuthenticated:!1,signinUri:`${t.identityHost}/signin/${t.environmentId}`});if(i.length===0)return r&&console.log("[Authdog] No cookies found, returning unauthenticated"),e;let c=i.find(s=>s.name===`user_session_hash_${t?.environmentId}`);if(c){r&&console.log("[Authdog] Found session hash cookie, attempting to fetch user data");let s=c.value,a=await g(t?.identityHost,t?.environmentId,s);return r&&console.log("[Authdog] User data fetch result:",{success:!!a,hasUser:!!a?.user,metaCode:a?.meta?.code}),m(a)?d({user:a.user,isAuthenticated:!0,signinUri:`${t.identityHost}/signin/${t.environmentId}`}):e}else r&&console.log("[Authdog] No session hash cookie found for environment:",t?.environmentId)}catch(n){console.error("[Authdog] Error authenticating with cookies:",n)}return null},h=async({request:o,context:t,params:n})=>{r&&console.log("[Authdog] Starting authentication loader");let i=n?.publicKey;if(!i)throw Error("[Authdog][Remix] Missing public key");let e=p(i);r&&console.log("[Authdog] Public key parsed:",{hasPublicKey:!!i,environmentId:e?.environmentId});let s=new URL(o.url).searchParams.get("token");if(r&&console.log("[Authdog] URL token check:",{hasToken:!!s}),s){r&&console.log("[Authdog] Processing token from URL");let u=await g(e?.identityHost,e?.environmentId,s);if(r&&console.log("[Authdog] Token authentication result:",{success:!!u,hasUser:!!u?.user,metaCode:u?.meta?.code}),m(u)){let A=JSON.stringify(u?.user);t[`user_session_${e?.environmentId}`]=A,t[`user_session_hash_${e?.environmentId}`]=s;let k=f(u,s,e?.environmentId,o);return d({user:u.user,isAuthenticated:!0,signinUri:`${e.identityHost}/signin/${e.environmentId}`},{headers:k.headers})}}r&&console.log("[Authdog] Attempting cookie authentication");let a=await y(o,e);return a?(r&&console.log("[Authdog] Cookie authentication successful"),a):(r&&console.log("[Authdog] No authentication methods succeeded, returning unauthenticated"),d({user:null,isAuthenticated:!1,signinUri:`${e.identityHost}/signin/${e.environmentId}`}))};import{redirect as H}from"@remix-run/node";import{validateAndParsePublicKey as R}from"@authdog/node-commons";var U=async({context:o,request:t})=>{let n=new Headers,i=process.env.PK_AUTHDOG;if(!i)throw new Error("Public key is not defined");let c=R(i).environmentId;return n.append("Set-Cookie",`user_session_${c}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Strict`),n.append("Set-Cookie",`user_session_hash_${c}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Strict`),H("/",{headers:n})};import{redirect as $}from"@remix-run/node";import{validateAndParsePublicKey as I,sanitizeRedirectPath as C}from"@authdog/node-commons";var L=()=>async({context:o,request:t})=>await h({request:t,context:o,params:{publicKey:process.env.PK_AUTHDOG}}),E=async({redirectTo:o="/"})=>{throw new Error("identityDevAction is not available in production")};export{v as AuthdogProvider,w as ReloadPage,y as authenticateWithCookies,f as createAuthResponse,E as identityDevAction,L as identityLoader,U as logoutLoader,h as remixAuthLoader};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/provider.tsx","../src/authLoader.ts","../src/logout.ts","../src/utils.ts"],"sourcesContent":["import 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 } else {\n // If we're on the server, don't show loading state\n setIsLoading(false);\n }\n }, []);\n\n // Show children while loading (don't return null)\n return <>{children}</>;\n};\n\nexport const ReloadPage = () => {\n useEffect(() => {\n if (typeof window !== \"undefined\") {\n const url = new URL(window.location.href);\n const token = url.searchParams.get(\"token\");\n if (token) {\n url.searchParams.delete(\"token\");\n window.history.replaceState({}, document.title, url.toString());\n localStorage.setItem(\"token\", token);\n return;\n }\n }\n }, []);\n return null;\n};\n","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 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\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 = 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 };","import { LoaderFunction, redirect } from \"@remix-run/node\";\n\nexport const logoutLoader: LoaderFunction = async ({ context, request }) => {\n const headers = new Headers();\n \n const publicKey = process.env.PK_AUTHDOG;\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n\n const payload = JSON.parse(\n Buffer.from(publicKey.replace(\"pk_\", \"\"), \"base64\").toString(\"utf-8\")\n );\n\n const environmentId = payload.environmentId;\n\n headers.append(\"Set-Cookie\", `user_session_${environmentId}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Strict`);\n headers.append(\"Set-Cookie\", `user_session_hash_${environmentId}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Strict`);\n\n return redirect(\"/\", { headers });\n};","import { LoaderFunction, redirect } from \"@remix-run/node\";\nimport { remixAuthLoader } from \"./authLoader\";\n\nexport const identityLoader = (): LoaderFunction => {\n return async ({ context, request }) => {\n return await remixAuthLoader({\n request,\n context,\n params: {\n publicKey: process.env.PK_AUTHDOG,\n },\n });\n };\n};\n\nexport const identityDevAction = async ({\n redirectTo = \"/\",\n}: {\n redirectTo: string;\n}) => {\n const publicKey = process.env.PK_AUTHDOG as string;\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n \n const payload = JSON.parse(\n Buffer.from(publicKey.replace(\"pk_\", \"\"), \"base64\").toString(\"utf-8\"),\n );\n \n const environmentId = payload.environmentId;\n const cookieNameSession = `user_session_${environmentId}`;\n const cookieNameHash = `user_session_hash_${environmentId}`;\n \n const response = redirect(redirectTo);\n \n response.headers.append(\n \"Set-Cookie\",\n `${cookieNameSession}=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=0`\n );\n response.headers.append(\n \"Set-Cookie\",\n `${c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AAMC,EAAgB,CAC3B,QAAAD,EACA,QAAAD,EACA,OAAQ,CACN,UAAW,QAAQ,IAAI,UACzB,CACF,CAAC,EAIQG,EAAoB,MAAO,CACpC,WAAAC,EAAa,GACjB,IAEM,CACF,IAAMC,EAAY,QAAQ,IAAI,WAC9B,GAAI,CAACA,EACH,MAAM,IAAI,MAAM,2BAA2B,EAO7C,IAAMC,EAJU,KAAK,MACnB,OAAO,KAAKD,EAAU,QAAQ,MAAO,EAAE,EAAG,QAAQ,EAAE,SAAS,OAAO,CACtE,EAE8B,cACxBE,EAAoB,gBAAgBD,CAAa,GACjDE,EAAiB,qBAAqBF,CAAa,GAEnDG,EAAWC,EAASN,CAAU,EAEpC,OAAAK,EAAS,QAAQ,OACf,aACA,GAAGF,CAAiB,yDACtB,EACAE,EAAS,QAAQ,OACf,aACA,GAAGD,CAAc,yDACnB,EAEOC,CACT","names":["useEffect","useState","Fragment","jsx","AuthdogProvider","children","isLoading","setIsLoading","url","ReloadPage","token","json","parseCookies","validateAndParsePublicKey","fetchUserData","createAuthResponse","authenticatedUser","token","environmentId","request","response","headers","userSessionValue","userSessionHashValue","publicKey","publicKeyObj","authenticateWithCookies","cookieHeader","cookies","userSessionHashCookie","c","error","remixAuthLoader","context","params","tokenFromUri","authResponse","cookieAuthResult","redirect","logoutLoader","context","request","headers","publicKey","environmentId","redirect","identityLoader","context","request","remixAuthLoader","identityDevAction","redirectTo","publicKey","environmentId","cookieNameSession","cookieNameHash","response","redirect"]}
1
+ {"version":3,"sources":["../src/provider.tsx","../src/authLoader.ts","../src/logout.ts","../src/utils.ts"],"sourcesContent":["import 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 } else {\n // If we're on the server, don't show loading state\n setIsLoading(false);\n }\n }, []);\n\n // Show children while loading (don't return null)\n return <>{children}</>;\n};\n\nexport const ReloadPage = () => {\n useEffect(() => {\n if (typeof window !== \"undefined\") {\n const url = new URL(window.location.href);\n const token = url.searchParams.get(\"token\");\n if (token) {\n // The server persists the session as HttpOnly cookies; the client\n // must not hold the raw token. Just strip it from the URL.\n url.searchParams.delete(\"token\");\n window.history.replaceState({}, document.title, url.toString());\n return;\n }\n }\n }, []);\n return null;\n};\n","import { json } from \"@remix-run/node\";\n\nimport {\n parseCookies,\n validateAndParsePublicKey,\n fetchUserData,\n isAuthenticatedUserInfo,\n} from \"@authdog/node-commons\";\n\nconst isDev = process.env.NODE_ENV !== \"production\";\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 if (isDev) {\n console.log(\"[Authdog] Creating auth response with:\", {\n hasUser: !!authenticatedUser?.user,\n environmentId,\n });\n }\n\n // Set cookies in the response headers\n const headers = new Headers();\n\n // Serialize the user object separately\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n const userSessionHashValue = token;\n\n if (isDev) {\n console.log(\"[Authdog] Setting cookies for environment:\", environmentId);\n }\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\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 if (isDev) {\n console.log(\n \"[Authdog] Attempting cookie authentication for environment:\",\n publicKeyObj?.environmentId,\n );\n }\n\n // Get cookies from request (parseCookies URL-decodes values)\n const cookieHeader = request.headers.get(\"Cookie\");\n const cookies = parseCookies(cookieHeader);\n\n const unauthenticated = json({\n user: null,\n isAuthenticated: false,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`,\n });\n\n if (cookies.length === 0) {\n if (isDev) {\n console.log(\"[Authdog] No cookies found, returning unauthenticated\");\n }\n return unauthenticated;\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 if (isDev) {\n console.log(\n \"[Authdog] Found session hash cookie, attempting to fetch user data\",\n );\n }\n const userSessionHashValue = userSessionHashCookie.value;\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n userSessionHashValue,\n );\n\n if (isDev) {\n console.log(\"[Authdog] User data fetch result:\", {\n success: !!authenticatedUser,\n hasUser: !!authenticatedUser?.user,\n metaCode: authenticatedUser?.meta?.code,\n });\n }\n\n if (!isAuthenticatedUserInfo(authenticatedUser)) {\n return unauthenticated;\n }\n\n return json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`,\n });\n } else if (isDev) {\n console.log(\n \"[Authdog] No session hash cookie found for environment:\",\n publicKeyObj?.environmentId,\n );\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 if (isDev) {\n console.log(\"[Authdog] Starting authentication loader\");\n }\n\n const publicKey = 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 if (isDev) {\n console.log(\"[Authdog] Public key parsed:\", {\n hasPublicKey: !!publicKey,\n environmentId: publicKeyObj?.environmentId,\n });\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 if (isDev) {\n console.log(\"[Authdog] URL token check:\", {\n hasToken: !!tokenFromUri,\n });\n }\n\n // If we have a token in URL, process it first\n if (tokenFromUri) {\n if (isDev) {\n console.log(\"[Authdog] Processing token from URL\");\n }\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n tokenFromUri,\n );\n\n if (isDev) {\n console.log(\"[Authdog] Token authentication result:\", {\n success: !!authenticatedUser,\n hasUser: !!authenticatedUser?.user,\n metaCode: authenticatedUser?.meta?.code,\n });\n }\n\n if (isAuthenticatedUserInfo(authenticatedUser)) {\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}`] =\n 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 if (isDev) {\n console.log(\"[Authdog] Attempting cookie authentication\");\n }\n const cookieAuthResult = await authenticateWithCookies(request, publicKeyObj);\n if (cookieAuthResult) {\n if (isDev) {\n console.log(\"[Authdog] Cookie authentication successful\");\n }\n return cookieAuthResult;\n }\n\n if (isDev) {\n console.log(\n \"[Authdog] No authentication methods succeeded, returning unauthenticated\",\n );\n }\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","import { LoaderFunction, redirect } from \"@remix-run/node\";\nimport { validateAndParsePublicKey } from \"@authdog/node-commons\";\n\nexport const logoutLoader: LoaderFunction = async ({ context, request }) => {\n const headers = new Headers();\n\n const publicKey = process.env.PK_AUTHDOG;\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n\n const publicKeyObj = validateAndParsePublicKey(publicKey);\n\n const environmentId = publicKeyObj.environmentId;\n\n headers.append(\n \"Set-Cookie\",\n `user_session_${environmentId}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Strict`,\n );\n headers.append(\n \"Set-Cookie\",\n `user_session_hash_${environmentId}=; Path=/; Max-Age=0; HttpOnly; Secure; SameSite=Strict`,\n );\n\n return redirect(\"/\", { headers });\n};\n","import { LoaderFunction, redirect } from \"@remix-run/node\";\nimport {\n validateAndParsePublicKey,\n sanitizeRedirectPath,\n} from \"@authdog/node-commons\";\nimport { remixAuthLoader } from \"./authLoader\";\n\nexport const identityLoader = (): LoaderFunction => {\n return async ({ context, request }) => {\n return await remixAuthLoader({\n request,\n context,\n params: {\n publicKey: process.env.PK_AUTHDOG,\n },\n });\n };\n};\n\nexport const identityDevAction = async ({\n redirectTo = \"/\",\n}: {\n redirectTo: string;\n}) => {\n if (process.env.NODE_ENV === \"production\") {\n throw new Error(\"identityDevAction is not available in production\");\n }\n\n const publicKey = process.env.PK_AUTHDOG as string;\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n\n const publicKeyObj = validateAndParsePublicKey(publicKey);\n\n const environmentId = publicKeyObj.environmentId;\n const cookieNameSession = `user_session_${environmentId}`;\n const cookieNameHash = `user_session_hash_${environmentId}`;\n\n const response = redirect(sanitizeRedirectPath(redirectTo));\n\n response.headers.append(\n \"Set-Cookie\",\n `${cookieNameSession}=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=0`,\n );\n response.headers.append(\n \"Set-Cookie\",\n `${cookieNameHash}=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=0`,\n );\n\n return response;\n};\n"],"mappings":"AAAA,OAAgB,aAAAA,EAAW,YAAAC,MAAgB,QAmClC,mBAAAC,EAAA,OAAAC,MAAA,oBAjCF,IAAMC,EAAkB,CAAC,CAC9B,SAAAC,CACF,IAEM,CACJ,GAAM,CAACC,EAAWC,CAAY,EAAIN,EAAS,EAAI,EAE/C,OAAAD,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,EACvB,MACF,CAGAD,EAAa,EAAK,CACpB,MAEEA,EAAa,EAAK,CAEtB,EAAG,CAAC,CAAC,EAGEJ,EAAAD,EAAA,CAAG,SAAAG,EAAS,CACrB,EAEaI,EAAa,KACxBT,EAAU,IAAM,CACd,GAAI,OAAO,OAAW,IAAa,CACjC,IAAMQ,EAAM,IAAI,IAAI,OAAO,SAAS,IAAI,EAExC,GADcA,EAAI,aAAa,IAAI,OAAO,EAC/B,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EAA0BK,CAAS,EAErB,cAEnC,OAAAD,EAAQ,OACN,aACA,gBAAgBE,CAAa,yDAC/B,EACAF,EAAQ,OACN,aACA,qBAAqBE,CAAa,yDACpC,EAEOP,EAAS,IAAK,CAAE,QAAAK,CAAQ,CAAC,CAClC,ECzBA,OAAyB,YAAAG,MAAgB,kBACzC,OACE,6BAAAC,EACA,wBAAAC,MACK,wBAGA,IAAMC,EAAiB,IACrB,MAAO,CAAE,QAAAC,EAAS,QAAAC,CAAQ,IACxB,MAAMC,EAAgB,CAC3B,QAAAD,EACA,QAAAD,EACA,OAAQ,CACN,UAAW,QAAQ,IAAI,UACzB,CACF,CAAC,EAIQG,EAAoB,MAAO,CACtC,WAAAC,EAAa,GACf,IAEM,CAEF,MAAM,IAAI,MAAM,kDAAkD,CA0BtE","names":["useEffect","useState","Fragment","jsx","AuthdogProvider","children","isLoading","setIsLoading","url","ReloadPage","json","parseCookies","validateAndParsePublicKey","fetchUserData","isAuthenticatedUserInfo","isDev","createAuthResponse","authenticatedUser","token","environmentId","request","headers","userSessionValue","userSessionHashValue","publicKey","publicKeyObj","authenticateWithCookies","cookieHeader","cookies","unauthenticated","userSessionHashCookie","c","error","remixAuthLoader","context","params","tokenFromUri","authResponse","cookieAuthResult","redirect","validateAndParsePublicKey","logoutLoader","context","request","headers","publicKey","environmentId","redirect","validateAndParsePublicKey","sanitizeRedirectPath","identityLoader","context","request","remixAuthLoader","identityDevAction","redirectTo"]}
package/package.json CHANGED
@@ -1,45 +1,61 @@
1
1
  {
2
- "name": "@authdog/remix-node",
3
- "version": "0.0.12",
4
- "description": "Authdog Remix SDK",
5
- "source": "src/index.ts",
6
- "main": "./dist/index.js",
7
- "module": "./dist/index.mjs",
8
- "types": "./dist/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.mjs",
13
- "require": "./dist/index.js"
2
+ "name": "@authdog/remix-node",
3
+ "version": "0.1.0",
4
+ "description": "Authdog Remix SDK",
5
+ "source": "src/index.ts",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.js"
14
+ },
15
+ "./client": {
16
+ "types": "./dist/client.d.ts",
17
+ "import": "./dist/client.mjs",
18
+ "require": "./dist/client.js"
19
+ }
14
20
  },
15
- "./client": {
16
- "types": "./dist/client.d.ts",
17
- "import": "./dist/client.mjs",
18
- "require": "./dist/client.js"
21
+ "files": [
22
+ "dist/"
23
+ ],
24
+ "sideEffects": false,
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/authdog-labs/web-sdk.git",
28
+ "directory": "packages/remix"
29
+ },
30
+ "homepage": "https://github.com/authdog-labs/web-sdk/tree/main/packages/remix#readme",
31
+ "bugs": {
32
+ "url": "https://github.com/authdog-labs/web-sdk/issues"
33
+ },
34
+ "scripts": {
35
+ "format": "prettier --config .prettierrc.json --write \"**/*.{ts,md}\"",
36
+ "type-check": "tsc",
37
+ "clean": "rm -rf dist",
38
+ "build": "bun run clean && tsup",
39
+ "ship": "bun run build && bun publish --access public"
40
+ },
41
+ "publishConfig": {
42
+ "registry": "https://registry.npmjs.org/",
43
+ "access": "public"
44
+ },
45
+ "dependencies": {
46
+ "@authdog/node-commons": "workspace:*"
47
+ },
48
+ "peerDependencies": {
49
+ "@remix-run/node": "^2.15.2 || ^2.16.0 || ^2.17.0",
50
+ "react": "^18.2.0 || ^19.0.0",
51
+ "react-dom": "^18.2.0 || ^19.0.0"
52
+ },
53
+ "devDependencies": {
54
+ "@remix-run/node": "^2.17.2",
55
+ "@types/node": "^22.14.1",
56
+ "@types/react": "^18.2.0",
57
+ "@types/react-dom": "^18.2.0",
58
+ "react": "^18.2.0",
59
+ "react-dom": "^18.2.0"
19
60
  }
20
- },
21
- "files": [
22
- "dist/"
23
- ],
24
- "publishConfig": {
25
- "registry": "https://registry.npmjs.org/",
26
- "access": "public"
27
- },
28
- "dependencies": {
29
- "@remix-run/node": "^2.15.2",
30
- "@remix-run/react": "^2.16.5",
31
- "react": "^18.2.0",
32
- "@authdog/node-commons": "0.0.22"
33
- },
34
- "devDependencies": {
35
- "@types/node": "^22.14.1",
36
- "@types/react": "^18.2.0"
37
- },
38
- "scripts": {
39
- "format": "prettier --config .prettierrc.json --write \"**/*.{ts,md}\"",
40
- "type-check": "tsc",
41
- "clean": "rm -rf dist",
42
- "build": "pnpm clean && tsup",
43
- "ship": "pnpm build && pnpm publish --access public --no-git-checks"
44
- }
45
- }
61
+ }