@authdog/remix-node 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.mts +9 -0
- package/dist/client.d.ts +9 -0
- package/dist/client.js +2 -0
- package/dist/client.js.map +1 -0
- package/dist/client.mjs +2 -0
- package/dist/client.mjs.map +1 -0
- package/dist/index.d.mts +11 -9
- package/dist/index.d.ts +11 -9
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
declare const AuthdogProvider: ({ children, }: {
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
7
|
+
declare const ReloadPage: () => null;
|
|
8
|
+
|
|
9
|
+
export { AuthdogProvider, ReloadPage };
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
declare const AuthdogProvider: ({ children, }: {
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
7
|
+
declare const ReloadPage: () => null;
|
|
8
|
+
|
|
9
|
+
export { AuthdogProvider, ReloadPage };
|
package/dist/client.js
ADDED
|
@@ -0,0 +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);
|
|
2
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +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"]}
|
package/dist/client.mjs
ADDED
|
@@ -0,0 +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};
|
|
2
|
+
//# sourceMappingURL=client.mjs.map
|
|
@@ -0,0 +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"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
+
export { AuthdogProvider, ReloadPage } from './client.mjs';
|
|
1
2
|
import * as _remix_run_node from '@remix-run/node';
|
|
2
3
|
import { LoaderFunction } from '@remix-run/node';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
declare const AuthdogProvider: ({ children, }: {
|
|
7
|
-
children: React.ReactNode;
|
|
8
|
-
}) => react_jsx_runtime.JSX.Element | null;
|
|
9
|
-
|
|
10
|
-
declare const logoutLoader: LoaderFunction;
|
|
4
|
+
import 'react/jsx-runtime';
|
|
5
|
+
import 'react';
|
|
11
6
|
|
|
12
7
|
declare const createAuthResponse: (authenticatedUser: any, token: string, environmentId: string, request: Request) => _remix_run_node.TypedResponse<{
|
|
13
8
|
user: any;
|
|
@@ -32,4 +27,11 @@ declare const remixAuthLoader: ({ request, context, params, }: IRemixAuthLoader)
|
|
|
32
27
|
signinUri: string;
|
|
33
28
|
}>>;
|
|
34
29
|
|
|
35
|
-
|
|
30
|
+
declare const logoutLoader: LoaderFunction;
|
|
31
|
+
|
|
32
|
+
declare const identityLoader: () => LoaderFunction;
|
|
33
|
+
declare const identityDevAction: ({ redirectTo, }: {
|
|
34
|
+
redirectTo: string;
|
|
35
|
+
}) => Promise<_remix_run_node.TypedResponse<never>>;
|
|
36
|
+
|
|
37
|
+
export { authenticateWithCookies, createAuthResponse, identityDevAction, identityLoader, logoutLoader, remixAuthLoader };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
+
export { AuthdogProvider, ReloadPage } from './client.js';
|
|
1
2
|
import * as _remix_run_node from '@remix-run/node';
|
|
2
3
|
import { LoaderFunction } from '@remix-run/node';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
declare const AuthdogProvider: ({ children, }: {
|
|
7
|
-
children: React.ReactNode;
|
|
8
|
-
}) => react_jsx_runtime.JSX.Element | null;
|
|
9
|
-
|
|
10
|
-
declare const logoutLoader: LoaderFunction;
|
|
4
|
+
import 'react/jsx-runtime';
|
|
5
|
+
import 'react';
|
|
11
6
|
|
|
12
7
|
declare const createAuthResponse: (authenticatedUser: any, token: string, environmentId: string, request: Request) => _remix_run_node.TypedResponse<{
|
|
13
8
|
user: any;
|
|
@@ -32,4 +27,11 @@ declare const remixAuthLoader: ({ request, context, params, }: IRemixAuthLoader)
|
|
|
32
27
|
signinUri: string;
|
|
33
28
|
}>>;
|
|
34
29
|
|
|
35
|
-
|
|
30
|
+
declare const logoutLoader: LoaderFunction;
|
|
31
|
+
|
|
32
|
+
declare const identityLoader: () => LoaderFunction;
|
|
33
|
+
declare const identityDevAction: ({ redirectTo, }: {
|
|
34
|
+
redirectTo: string;
|
|
35
|
+
}) => Promise<_remix_run_node.TypedResponse<never>>;
|
|
36
|
+
|
|
37
|
+
export { authenticateWithCookies, createAuthResponse, identityDevAction, identityLoader, logoutLoader, remixAuthLoader };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
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};
|
|
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/logout.ts"],"sourcesContent":["import { json } from \"@remix-run/node\";\n\nimport {\n parseCookies,\n validateAndParsePublicKey,\n fetchUserData,\n} from \"@authdog/node-commons\";\n\n// Function to create authentication response with cookies\nexport const createAuthResponse = (\n authenticatedUser: any,\n token: string,\n environmentId: string,\n request: Request,\n) => {\n\n\n console.log(\"[Authdog] Creating auth response with:\", {\n hasUser: !!authenticatedUser?.user,\n environmentId,\n tokenLength: token?.length,\n });\n\n // Create response with cookies\n const response = json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n });\n\n // Set cookies in the response headers\n const headers = new Headers(response.headers);\n\n // Serialize the user object separately\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n const userSessionHashValue = token;\n\n console.log(\"[Authdog] Setting cookies for environment:\", environmentId);\n\n headers.append(\n \"Set-Cookie\",\n `user_session_${environmentId}=${encodeURIComponent(userSessionValue)}; Path=/; HttpOnly; Secure; SameSite=Strict`,\n );\n headers.append(\n \"Set-Cookie\",\n `user_session_hash_${environmentId}=${encodeURIComponent(userSessionHashValue)}; Path=/; HttpOnly; Secure; SameSite=Strict`,\n );\n\n // Add cache control headers\n headers.append(\n \"Cache-Control\",\n \"no-store, no-cache, must-revalidate, proxy-revalidate\",\n );\n headers.append(\"Pragma\", \"no-cache\");\n headers.append(\"Expires\", \"0\");\n headers.append(\"Vary\", \"Cookie\");\n headers.append(\"Content-Type\", \"application/json\");\n headers.append(\"Access-Control-Allow-Origin\", \"*\");\n headers.append(\"Access-Control-Allow-Credentials\", \"true\");\n\n const publicKey = process.env.PK_AUTHDOG as string;\n\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n\n const publicKeyObj = validateAndParsePublicKey(publicKey)\n\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n },\n {\n headers,\n },\n );\n};\n\n// Function to authenticate with cookies\nexport const authenticateWithCookies = async (\n request: Request,\n publicKeyObj: any,\n) => {\n try {\n console.log(\"[Authdog] Attempting cookie authentication for environment:\", publicKeyObj?.environmentId);\n \n // Get cookies from request\n const cookieHeader = request.headers.get(\"Cookie\");\n const cookies = parseCookies(cookieHeader);\n\n if (cookies.length === 0) {\n console.log(\"[Authdog] No cookies found, returning unauthenticated\");\n return json({\n user: null,\n isAuthenticated: false,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n });\n }\n\n // Find our specific cookies\n const userSessionHashCookie = cookies.find(\n (c: any) => c.name === `user_session_hash_${publicKeyObj?.environmentId}`,\n );\n\n if (userSessionHashCookie) {\n console.log(\"[Authdog] Found session hash cookie, attempting to fetch user data\");\n const userSessionHashValue = userSessionHashCookie.value;\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n userSessionHashValue,\n );\n\n console.log(\"[Authdog] User data fetch result:\", {\n success: !!authenticatedUser,\n hasUser: !!authenticatedUser?.user,\n metaCode: authenticatedUser?.meta?.code,\n });\n\n return json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n\n });\n } else {\n console.log(\"[Authdog] No session hash cookie found for environment:\", publicKeyObj?.environmentId);\n }\n } catch (error) {\n console.error(\"[Authdog] Error authenticating with cookies:\", error);\n }\n\n return null;\n};\n\ninterface IRemixAuthLoader {\n request: Request;\n context: Record<string, any>;\n params: {\n publicKey?: string;\n }\n}\n\n// Main loader function\nexport const remixAuthLoader = async ({\n request,\n context,\n params,\n}: IRemixAuthLoader) => {\n console.log(\"[Authdog] Starting authentication loader\");\n \n const publicKey =\n typeof process !== \"undefined\"\n ? (process.env.PK_AUTHDOG as string)\n : params?.publicKey as string\n\n if (!publicKey) {\n throw Error(\"[Authdog][Remix] Missing public key\")\n }\n\n const publicKeyObj = validateAndParsePublicKey(publicKey);\n\n console.log(\"[Authdog] Public key parsed:\", {\n hasPublicKey: !!publicKey,\n environmentId: publicKeyObj?.environmentId,\n });\n\n // First check if we have a token in the URL\n const url = new URL(request.url);\n const tokenFromUri = url.searchParams.get(\"token\");\n\n console.log(\"[Authdog] URL token check:\", {\n hasToken: !!tokenFromUri,\n tokenLength: tokenFromUri?.length,\n });\n\n // If we have a token in URL, process it first\n if (tokenFromUri) {\n console.log(\"[Authdog] Processing token from URL\");\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n tokenFromUri,\n );\n\n console.log(\"[Authdog] Token authentication result:\", {\n success: !!authenticatedUser,\n hasUser: !!authenticatedUser?.user,\n metaCode: authenticatedUser?.meta?.code,\n });\n\n if (authenticatedUser?.meta && authenticatedUser?.meta?.code === 200) {\n // Store in context for later use\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n context[`user_session_${publicKeyObj?.environmentId}`] = userSessionValue;\n context[`user_session_hash_${publicKeyObj?.environmentId}`] = tokenFromUri;\n\n // Create the response with auth data\n const authResponse = createAuthResponse(\n authenticatedUser,\n tokenFromUri,\n publicKeyObj?.environmentId,\n request,\n );\n\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n },\n {\n headers: authResponse.headers,\n },\n );\n }\n }\n\n // If no token in URL or token authentication failed, try cookie authentication\n console.log(\"[Authdog] Attempting cookie authentication\");\n const cookieAuthResult = await authenticateWithCookies(request, publicKeyObj);\n if (cookieAuthResult) {\n console.log(\"[Authdog] Cookie authentication successful\");\n return cookieAuthResult;\n }\n\n console.log(\"[Authdog] No authentication methods succeeded, returning unauthenticated\");\n // If we get here, we're not authenticated\n return json({\n user: null,\n isAuthenticated: false,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n });\n};\n\nexport { AuthdogProvider } from \"./provider\";\nexport {logoutLoader} from \"./logout\"","\"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","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};"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,4BAAAC,EAAA,uBAAAC,EAAA,iBAAAC,EAAA,oBAAAC,IAAA,eAAAC,EAAAP,GAAA,IAAAQ,EAAqB,2BAErBC,EAIO,iCCLP,IAAAC,EAA2C,iBAoClCC,EAAA,6BAlC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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","logoutLoader","remixAuthLoader","__toCommonJS","import_node","import_node_commons","import_react","import_jsx_runtime","AuthdogProvider","children","isLoading","setIsLoading","url","import_node","logoutLoader","context","request","headers","publicKey","environmentId","createAuthResponse","authenticatedUser","token","environmentId","request","response","headers","userSessionValue","userSessionHashValue","publicKey","publicKeyObj","authenticateWithCookies","cookieHeader","cookies","userSessionHashCookie","c","error","remixAuthLoader","context","params","tokenFromUri","authResponse","cookieAuthResult"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/provider.tsx","../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,EACn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OAAO,aAAc,qBAAqBE,CAAa,yDAAyD,KAEjH,YAAS,IAAK,CAAE,QAAAF,CAAQ,CAAC,CAClC,ECpBA,IAAAG,EAAyC,2BAGlC,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"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
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};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/provider.tsx","../src/logout.ts"],"sourcesContent":["import { json } from \"@remix-run/node\";\n\nimport {\n parseCookies,\n validateAndParsePublicKey,\n fetchUserData,\n} from \"@authdog/node-commons\";\n\n// Function to create authentication response with cookies\nexport const createAuthResponse = (\n authenticatedUser: any,\n token: string,\n environmentId: string,\n request: Request,\n) => {\n\n\n console.log(\"[Authdog] Creating auth response with:\", {\n hasUser: !!authenticatedUser?.user,\n environmentId,\n tokenLength: token?.length,\n });\n\n // Create response with cookies\n const response = json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n });\n\n // Set cookies in the response headers\n const headers = new Headers(response.headers);\n\n // Serialize the user object separately\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n const userSessionHashValue = token;\n\n console.log(\"[Authdog] Setting cookies for environment:\", environmentId);\n\n headers.append(\n \"Set-Cookie\",\n `user_session_${environmentId}=${encodeURIComponent(userSessionValue)}; Path=/; HttpOnly; Secure; SameSite=Strict`,\n );\n headers.append(\n \"Set-Cookie\",\n `user_session_hash_${environmentId}=${encodeURIComponent(userSessionHashValue)}; Path=/; HttpOnly; Secure; SameSite=Strict`,\n );\n\n // Add cache control headers\n headers.append(\n \"Cache-Control\",\n \"no-store, no-cache, must-revalidate, proxy-revalidate\",\n );\n headers.append(\"Pragma\", \"no-cache\");\n headers.append(\"Expires\", \"0\");\n headers.append(\"Vary\", \"Cookie\");\n headers.append(\"Content-Type\", \"application/json\");\n headers.append(\"Access-Control-Allow-Origin\", \"*\");\n headers.append(\"Access-Control-Allow-Credentials\", \"true\");\n\n const publicKey = process.env.PK_AUTHDOG as string;\n\n if (!publicKey) {\n throw new Error(\"Public key is not defined\");\n }\n\n const publicKeyObj = validateAndParsePublicKey(publicKey)\n\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n },\n {\n headers,\n },\n );\n};\n\n// Function to authenticate with cookies\nexport const authenticateWithCookies = async (\n request: Request,\n publicKeyObj: any,\n) => {\n try {\n console.log(\"[Authdog] Attempting cookie authentication for environment:\", publicKeyObj?.environmentId);\n \n // Get cookies from request\n const cookieHeader = request.headers.get(\"Cookie\");\n const cookies = parseCookies(cookieHeader);\n\n if (cookies.length === 0) {\n console.log(\"[Authdog] No cookies found, returning unauthenticated\");\n return json({\n user: null,\n isAuthenticated: false,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n });\n }\n\n // Find our specific cookies\n const userSessionHashCookie = cookies.find(\n (c: any) => c.name === `user_session_hash_${publicKeyObj?.environmentId}`,\n );\n\n if (userSessionHashCookie) {\n console.log(\"[Authdog] Found session hash cookie, attempting to fetch user data\");\n const userSessionHashValue = userSessionHashCookie.value;\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n userSessionHashValue,\n );\n\n console.log(\"[Authdog] User data fetch result:\", {\n success: !!authenticatedUser,\n hasUser: !!authenticatedUser?.user,\n metaCode: authenticatedUser?.meta?.code,\n });\n\n return json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n\n });\n } else {\n console.log(\"[Authdog] No session hash cookie found for environment:\", publicKeyObj?.environmentId);\n }\n } catch (error) {\n console.error(\"[Authdog] Error authenticating with cookies:\", error);\n }\n\n return null;\n};\n\ninterface IRemixAuthLoader {\n request: Request;\n context: Record<string, any>;\n params: {\n publicKey?: string;\n }\n}\n\n// Main loader function\nexport const remixAuthLoader = async ({\n request,\n context,\n params,\n}: IRemixAuthLoader) => {\n console.log(\"[Authdog] Starting authentication loader\");\n \n const publicKey =\n typeof process !== \"undefined\"\n ? (process.env.PK_AUTHDOG as string)\n : params?.publicKey as string\n\n if (!publicKey) {\n throw Error(\"[Authdog][Remix] Missing public key\")\n }\n\n const publicKeyObj = validateAndParsePublicKey(publicKey);\n\n console.log(\"[Authdog] Public key parsed:\", {\n hasPublicKey: !!publicKey,\n environmentId: publicKeyObj?.environmentId,\n });\n\n // First check if we have a token in the URL\n const url = new URL(request.url);\n const tokenFromUri = url.searchParams.get(\"token\");\n\n console.log(\"[Authdog] URL token check:\", {\n hasToken: !!tokenFromUri,\n tokenLength: tokenFromUri?.length,\n });\n\n // If we have a token in URL, process it first\n if (tokenFromUri) {\n console.log(\"[Authdog] Processing token from URL\");\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n tokenFromUri,\n );\n\n console.log(\"[Authdog] Token authentication result:\", {\n success: !!authenticatedUser,\n hasUser: !!authenticatedUser?.user,\n metaCode: authenticatedUser?.meta?.code,\n });\n\n if (authenticatedUser?.meta && authenticatedUser?.meta?.code === 200) {\n // Store in context for later use\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n context[`user_session_${publicKeyObj?.environmentId}`] = userSessionValue;\n context[`user_session_hash_${publicKeyObj?.environmentId}`] = tokenFromUri;\n\n // Create the response with auth data\n const authResponse = createAuthResponse(\n authenticatedUser,\n tokenFromUri,\n publicKeyObj?.environmentId,\n request,\n );\n\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n },\n {\n headers: authResponse.headers,\n },\n );\n }\n }\n\n // If no token in URL or token authentication failed, try cookie authentication\n console.log(\"[Authdog] Attempting cookie authentication\");\n const cookieAuthResult = await authenticateWithCookies(request, publicKeyObj);\n if (cookieAuthResult) {\n console.log(\"[Authdog] Cookie authentication successful\");\n return cookieAuthResult;\n }\n\n console.log(\"[Authdog] No authentication methods succeeded, returning unauthenticated\");\n // If we get here, we're not authenticated\n return json({\n user: null,\n isAuthenticated: false,\n signinUri: `${publicKeyObj.identityHost}/signin/${publicKeyObj.environmentId}`\n });\n};\n\nexport { AuthdogProvider } from \"./provider\";\nexport {logoutLoader} from \"./logout\"","\"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","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};"],"mappings":"AAAA,OAAS,QAAAA,MAAY,kBAErB,OACE,gBAAAC,EACA,6BAAAC,EACA,iBAAAC,MACK,wBCLP,OAAgB,aAAAC,EAAW,YAAAC,MAAgB,QAoClC,mBAAAC,EAAA,OAAAC,MAAA,oBAlCF,IAAMC,EAAkB,CAAC,CAC9B,SAAAC,CACF,IAEM,CACJ,GAAM,CAACC,EAAWC,CAAY,EAAIN,EAAS,EAAI,EAyB/C,OAvBAD,EAAU,IAAM,CAEd,GAAI,OAAO,OAAW,IAAa,CAEjC,IAAMQ,EAAM,IAAI,IAAI,OAAO,SAAS,IAAI,EAGxC,GAFcA,EAAI,aAAa,IAAI,OAAO,EAE/B,CAETA,EAAI,aAAa,OAAO,OAAO,EAC/B,OAAO,QAAQ,aAAa,CAAC,EAAG,SAAS,MAAOA,EAAI,SAAS,CAAC,EAG9D,OAAO,SAAS,OAAO,EACvB,MACF,CAGAD,EAAa,EAAK,CACpB,CACF,EAAG,CAAC,CAAC,EAGDD,EACK,KAGFH,EAAAD,EAAA,CAAG,SAAAG,EAAS,CACrB,ECtCA,OAAyB,YAAAI,MAAgB,kBAElC,IAAMC,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,EAO7C,IAAMC,EAJU,KAAK,MACnB,OAAO,KAAKD,EAAU,QAAQ,MAAO,EAAE,EAAG,QAAQ,EAAE,SAAS,OAAO,CACt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AAI,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","redirect","logoutLoader","context","request","headers","publicKey","environmentId","createAuthResponse","authenticatedUser","token","environmentId","request","response","json","headers","userSessionValue","userSessionHashValue","publicKey","publicKeyObj","validateAndParsePublicKey","authenticateWithCookies","cookieHeader","cookies","parseCookies","userSessionHashCookie","c","fetchUserData","error","remixAuthLoader","context","params","tokenFromUri","authResponse","cookieAuthResult"]}
|
|
1
|
+
{"version":3,"sources":["../src/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 `${cookieNameHash}=; Path=/; HttpOnly; Secure; SameSite=Strict; Max-Age=0`\n );\n \n return response;\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,EACl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C,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,cAE9B,OAAAD,EAAQ,OAAO,aAAc,gBAAgBE,CAAa,yDAAyD,EACnHF,EAAQ,OAAO,aAAc,qBAAqBE,CAAa,yDAAyD,EAEjHN,EAAS,IAAK,CAAE,QAAAI,CAAQ,CAAC,CAClC,ECpBA,OAAyB,YAAAG,MAAgB,kBAGlC,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,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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authdog/remix-node",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"description": "Authdog Remix SDK",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,6 +11,11 @@
|
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"import": "./dist/index.mjs",
|
|
13
13
|
"require": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./client": {
|
|
16
|
+
"types": "./dist/client.d.ts",
|
|
17
|
+
"import": "./dist/client.mjs",
|
|
18
|
+
"require": "./dist/client.js"
|
|
14
19
|
}
|
|
15
20
|
},
|
|
16
21
|
"files": [
|