@authdog/remix-node 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import * as _remix_run_node from '@remix-run/node';
|
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
|
|
5
|
-
declare const AuthdogProvider: ({ children }: {
|
|
5
|
+
declare const AuthdogProvider: ({ children, }: {
|
|
6
6
|
children: React.ReactNode;
|
|
7
7
|
}) => react_jsx_runtime.JSX.Element | null;
|
|
8
8
|
|
|
@@ -14,7 +14,7 @@ declare const authenticateWithCookies: (request: Request, publicKeyObj: any) =>
|
|
|
14
14
|
user: any;
|
|
15
15
|
isAuthenticated: boolean;
|
|
16
16
|
}> | null>;
|
|
17
|
-
declare const remixAuthLoader: ({ request, context, params }: {
|
|
17
|
+
declare const remixAuthLoader: ({ request, context, params, }: {
|
|
18
18
|
request: Request;
|
|
19
19
|
context: Record<string, any>;
|
|
20
20
|
params: any;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as _remix_run_node from '@remix-run/node';
|
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
|
|
5
|
-
declare const AuthdogProvider: ({ children }: {
|
|
5
|
+
declare const AuthdogProvider: ({ children, }: {
|
|
6
6
|
children: React.ReactNode;
|
|
7
7
|
}) => react_jsx_runtime.JSX.Element | null;
|
|
8
8
|
|
|
@@ -14,7 +14,7 @@ declare const authenticateWithCookies: (request: Request, publicKeyObj: any) =>
|
|
|
14
14
|
user: any;
|
|
15
15
|
isAuthenticated: boolean;
|
|
16
16
|
}> | null>;
|
|
17
|
-
declare const remixAuthLoader: ({ request, context, params }: {
|
|
17
|
+
declare const remixAuthLoader: ({ request, context, params, }: {
|
|
18
18
|
request: Request;
|
|
19
19
|
context: Record<string, any>;
|
|
20
20
|
params: any;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/provider.tsx"],"sourcesContent":["import { json } from \"@remix-run/node\";\n\nimport { parseCookies, validateAndParsePublicKey, fetchUserData } from \"@authdog/node-commons\";\n\n// Function to create authentication response with cookies\nexport const createAuthResponse = (\n authenticatedUser: any,\n token: string,\n environmentId: string,\n request: Request,\n) => {\n // Create response with cookies\n const response = json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n });\n\n // Set cookies in the response headers\n const headers = new Headers(response.headers);\n\n // Serialize the user object separately\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n const userSessionHashValue = token;\n\n headers.append(\n \"Set-Cookie\",\n `user_session_${environmentId}=${encodeURIComponent(userSessionValue)}; Path=/; HttpOnly; Secure; SameSite=Strict`,\n );\n headers.append(\n \"Set-Cookie\",\n `user_session_hash_${environmentId}=${encodeURIComponent(userSessionHashValue)}; Path=/; HttpOnly; Secure; SameSite=Strict`,\n );\n\n // Add cache control headers\n headers.append(\n \"Cache-Control\",\n \"no-store, no-cache, must-revalidate, proxy-revalidate\",\n );\n headers.append(\"Pragma\", \"no-cache\");\n headers.append(\"Expires\", \"0\");\n headers.append(\"Vary\", \"Cookie\");\n headers.append(\"Content-Type\", \"application/json\");\n headers.append(\"Access-Control-Allow-Origin\", \"*\");\n headers.append(\"Access-Control-Allow-Credentials\", \"true\");\n\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n },\n {\n headers,\n },\n );\n};\n\n// Function to authenticate with cookies\nexport const authenticateWithCookies = async (\n request: Request,\n publicKeyObj: any,\n) => {\n try {\n // Get cookies from request\n const cookieHeader = request.headers.get(\"Cookie\");\n const cookies = parseCookies(cookieHeader);\n\n if (cookies.length === 0) {\n return json({\n user: null,\n isAuthenticated: false,\n });\n }\n\n // Find our specific cookies\n const userSessionHashCookie = cookies.find(\n (c: any) => c.name === `user_session_hash_${publicKeyObj?.environmentId}`,\n );\n\n if (userSessionHashCookie) {\n const userSessionHashValue = userSessionHashCookie.value;\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n userSessionHashValue,\n );\n\n return json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n });\n }\n } catch (error) {\n console.error(\"Error authenticating with cookies:\", error);\n }\n\n return null;\n};\n\n// Main loader function\nexport const remixAuthLoader = async ({\n request,\n context,\n params\n}: {\n request: Request;\n context: Record<string, any>;\n params: any;\n}) => {\n const publicKey = typeof process !== \"undefined\" ? process.env.PK_AUTHDOG as string\n : params?.publicKey;\n const publicKeyObj = validateAndParsePublicKey(publicKey);\n\n // First check if we have a token in the URL\n const url = new URL(request.url);\n const tokenFromUri = url.searchParams.get(\"token\");\n\n // Try to authenticate using cookies first\n const cookieAuthResult = await authenticateWithCookies(\n request,\n publicKeyObj,\n );\n \n if (cookieAuthResult) {\n // If we have a token in URL, still process it but don't show loading\n if (tokenFromUri) {\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n tokenFromUri,\n );\n\n if (authenticatedUser?.meta && authenticatedUser?.meta?.code === 200) {\n // Store in context for later use\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n context[`user_session_${publicKeyObj?.environmentId}`] = userSessionValue;\n context[`user_session_hash_${publicKeyObj?.environmentId}`] = tokenFromUri;\n\n // Create the response with auth data\n const authResponse = createAuthResponse(\n authenticatedUser,\n tokenFromUri,\n publicKeyObj?.environmentId,\n request,\n );\n\n // Return the response with cookies but don't redirect\n // The client-side reload will handle the URL cleanup\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n },\n {\n headers: authResponse.headers,\n }\n );\n }\n }\n return cookieAuthResult;\n }\n\n // If we have a token but no cookie auth, show loading while processing token\n if (tokenFromUri) {\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n tokenFromUri,\n );\n\n if (authenticatedUser?.meta && authenticatedUser?.meta?.code === 200) {\n // Store in context for later use\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n context[`user_session_${publicKeyObj?.environmentId}`] = userSessionValue;\n context[`user_session_hash_${publicKeyObj?.environmentId}`] = tokenFromUri;\n\n // Create the response with auth data\n const authResponse = createAuthResponse(\n authenticatedUser,\n tokenFromUri,\n publicKeyObj?.environmentId,\n request,\n );\n\n // Return the response with cookies but don't redirect\n // The client-side reload will handle the URL cleanup\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n },\n {\n headers: authResponse.headers,\n }\n );\n }\n return json({ loading: true });\n }\n\n // If we get here, we're not authenticated and not loading\n return json({\n user: null,\n isAuthenticated: false,\n });\n};\n\nexport {AuthdogProvider} from \"./provider.tsx\"","\"use client\";\nimport React, { useEffect, useState } from \"react\";\n\nexport const AuthdogProvider = ({ children }: { children: React.ReactNode }) => {\n const [isLoading, setIsLoading] = useState(true);\n\n useEffect(() => {\n // Check if we're in the browser\n if (typeof window !== 'undefined') {\n // Check if there's a token in the URL\n const url = new URL(window.location.href);\n const token = url.searchParams.get(\"token\");\n \n if (token) {\n // Remove token from URL without triggering a page reload\n url.searchParams.delete(\"token\");\n window.history.replaceState({}, document.title, url.toString());\n \n // Force a reload to ensure the server processes the token\n window.location.reload();\n return;\n }\n \n // If no token, we're done loading\n setIsLoading(false);\n }\n }, []);\n\n // Show nothing while loading\n if (isLoading) {\n return null;\n }\n\n return <>{children}</>;\n};"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,4BAAAC,EAAA,uBAAAC,EAAA,oBAAAC,IAAA,eAAAC,EAAAN,GAAA,IAAAO,EAAqB,2BAErBC,EAAuE,iCCDvE,I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a,OACxB,CACF,CACF,CACF,CACA,OAAOD,CACT,CAGA,GAAID,EAAc,CAChB,IAAMnB,EAAoB,QAAM,iBAC9BS,GAAc,aACdA,GAAc,cACdU,CACF,EAEA,GAAInB,GAAmB,MAAQA,GAAmB,MAAM,OAAS,IAAK,CAEpE,IAAMM,EAAmB,KAAK,UAAUN,GAAmB,IAAI,EAC/DgB,EAAQ,gBAAgBP,GAAc,aAAa,EAAE,EAAIH,EACzDU,EAAQ,qBAAqBP,GAAc,aAAa,EAAE,EAAIU,EAG9D,IAAME,EAAetB,EACnBC,EACAmB,EACAV,GAAc,cACdN,CACF,EAIA,SAAO,QACL,CACE,KAAMH,EAAkB,KACxB,gBAAiB,EACnB,EACA,CACE,QAASqB,EAAa,OACxB,CACF,CACF,CACA,SAAO,QAAK,CAAE,QAAS,EAAK,CAAC,CAC/B,CAGA,SAAO,QAAK,CACV,KAAM,KACN,gBAAiB,EACnB,CAAC,CACH","names":["index_exports","__export","AuthdogProvider","authenticateWithCookies","createAuthResponse","remixAuthLoader","__toCommonJS","import_node","import_node_commons","import_react","import_jsx_runtime","AuthdogProvider","children","isLoading","setIsLoading","url","createAuthResponse","authenticatedUser","token","environmentId","request","response","headers","userSessionValue","userSessionHashValue","authenticateWithCookies","publicKeyObj","cookieHeader","cookies","userSessionHashCookie","c","error","remixAuthLoader","context","params","publicKey","tokenFromUri","cookieAuthResult","authResponse"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/provider.tsx"],"sourcesContent":["import { json } from \"@remix-run/node\";\n\nimport {\n parseCookies,\n validateAndParsePublicKey,\n fetchUserData,\n} from \"@authdog/node-commons\";\n\n// Function to create authentication response with cookies\nexport const createAuthResponse = (\n authenticatedUser: any,\n token: string,\n environmentId: string,\n request: Request,\n) => {\n // Create response with cookies\n const response = json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n });\n\n // Set cookies in the response headers\n const headers = new Headers(response.headers);\n\n // Serialize the user object separately\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n const userSessionHashValue = token;\n\n headers.append(\n \"Set-Cookie\",\n `user_session_${environmentId}=${encodeURIComponent(userSessionValue)}; Path=/; HttpOnly; Secure; SameSite=Strict`,\n );\n headers.append(\n \"Set-Cookie\",\n `user_session_hash_${environmentId}=${encodeURIComponent(userSessionHashValue)}; Path=/; HttpOnly; Secure; SameSite=Strict`,\n );\n\n // Add cache control headers\n headers.append(\n \"Cache-Control\",\n \"no-store, no-cache, must-revalidate, proxy-revalidate\",\n );\n headers.append(\"Pragma\", \"no-cache\");\n headers.append(\"Expires\", \"0\");\n headers.append(\"Vary\", \"Cookie\");\n headers.append(\"Content-Type\", \"application/json\");\n headers.append(\"Access-Control-Allow-Origin\", \"*\");\n headers.append(\"Access-Control-Allow-Credentials\", \"true\");\n\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n },\n {\n headers,\n },\n );\n};\n\n// Function to authenticate with cookies\nexport const authenticateWithCookies = async (\n request: Request,\n publicKeyObj: any,\n) => {\n try {\n // Get cookies from request\n const cookieHeader = request.headers.get(\"Cookie\");\n const cookies = parseCookies(cookieHeader);\n\n if (cookies.length === 0) {\n return json({\n user: null,\n isAuthenticated: false,\n });\n }\n\n // Find our specific cookies\n const userSessionHashCookie = cookies.find(\n (c: any) => c.name === `user_session_hash_${publicKeyObj?.environmentId}`,\n );\n\n if (userSessionHashCookie) {\n const userSessionHashValue = userSessionHashCookie.value;\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n userSessionHashValue,\n );\n\n return json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n });\n }\n } catch (error) {\n console.error(\"Error authenticating with cookies:\", error);\n }\n\n return null;\n};\n\n// Main loader function\nexport const remixAuthLoader = async ({\n request,\n context,\n params,\n}: {\n request: Request;\n context: Record<string, any>;\n params: any;\n}) => {\n const publicKey =\n typeof process !== \"undefined\"\n ? (process.env.PK_AUTHDOG as string)\n : params?.publicKey;\n const publicKeyObj = validateAndParsePublicKey(publicKey);\n\n // First check if we have a token in the URL\n const url = new URL(request.url);\n const tokenFromUri = url.searchParams.get(\"token\");\n\n // Try to authenticate using cookies first\n const cookieAuthResult = await authenticateWithCookies(request, publicKeyObj);\n\n if (cookieAuthResult) {\n // If we have a token in URL, still process it but don't show loading\n if (tokenFromUri) {\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n tokenFromUri,\n );\n\n if (authenticatedUser?.meta && authenticatedUser?.meta?.code === 200) {\n // Store in context for later use\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n context[`user_session_${publicKeyObj?.environmentId}`] =\n 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 the response with cookies but don't redirect\n // The client-side reload will handle the URL cleanup\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n },\n {\n headers: authResponse.headers,\n },\n );\n }\n }\n return cookieAuthResult;\n }\n\n // If we have a token but no cookie auth, show loading while processing token\n if (tokenFromUri) {\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n tokenFromUri,\n );\n\n if (authenticatedUser?.meta && authenticatedUser?.meta?.code === 200) {\n // Store in context for later use\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n context[`user_session_${publicKeyObj?.environmentId}`] = userSessionValue;\n context[`user_session_hash_${publicKeyObj?.environmentId}`] =\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 the response with cookies but don't redirect\n // The client-side reload will handle the URL cleanup\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n },\n {\n headers: authResponse.headers,\n },\n );\n }\n return json({ loading: true });\n }\n\n // If we get here, we're not authenticated and not loading\n return json({\n user: null,\n isAuthenticated: false,\n });\n};\n\nexport { AuthdogProvider } from \"./provider.tsx\";\n","\"use client\";\nimport React, { useEffect, useState } from \"react\";\n\nexport const AuthdogProvider = ({\n children,\n}: {\n children: React.ReactNode;\n}) => {\n const [isLoading, setIsLoading] = useState(true);\n\n useEffect(() => {\n // Check if we're in the browser\n if (typeof window !== \"undefined\") {\n // Check if there's a token in the URL\n const url = new URL(window.location.href);\n const token = url.searchParams.get(\"token\");\n\n if (token) {\n // Remove token from URL without triggering a page reload\n url.searchParams.delete(\"token\");\n window.history.replaceState({}, document.title, url.toString());\n\n // Force a reload to ensure the server processes the token\n window.location.reload();\n return;\n }\n\n // If no token, we're done loading\n setIsLoading(false);\n }\n }, []);\n\n // Show nothing while loading\n if (isLoading) {\n return null;\n }\n\n return <>{children}</>;\n};\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,4BAAAC,EAAA,uBAAAC,EAAA,oBAAAC,IAAA,eAAAC,EAAAN,GAAA,IAAAO,EAAqB,2BAErBC,EAIO,iCCLP,IAAAC,EAA2C,iBAoClCC,EAAA,6BAlCIC,EAAkB,CAAC,CAC9B,SAAAC,CACF,IAEM,CACJ,GAAM,CAACC,EAAWC,CAAY,KAAI,YAAS,EAAI,EAyB/C,SAvBA,aAAU,IAAM,CAEd,GAAI,OAAO,OAAW,IAAa,CAEjC,IAAMC,EAAM,IAAI,IAAI,OAAO,SAAS,IAAI,EAGxC,GAFcA,EAAI,aAAa,IAAI,OAAO,EAE/B,CAETA,EAAI,aAAa,OAAO,OAAO,EAC/B,OAAO,QAAQ,aAAa,CAAC,EAAG,SAAS,MAAOA,EAAI,SAAS,CAAC,EAG9D,OAAO,SAAS,OAAO,EACvB,MACF,CAGAD,EAAa,EAAK,CACpB,CACF,EAAG,CAAC,CAAC,EAGDD,EACK,QAGF,mBAAG,SAAAD,EAAS,CACrB,ED7BO,IAAMI,EAAqB,CA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AAK,CACV,KAAM,KACN,gBAAiB,EACnB,CAAC,CACH","names":["index_exports","__export","AuthdogProvider","authenticateWithCookies","createAuthResponse","remixAuthLoader","__toCommonJS","import_node","import_node_commons","import_react","import_jsx_runtime","AuthdogProvider","children","isLoading","setIsLoading","url","createAuthResponse","authenticatedUser","token","environmentId","request","response","headers","userSessionValue","userSessionHashValue","authenticateWithCookies","publicKeyObj","cookieHeader","cookies","userSessionHashCookie","c","error","remixAuthLoader","context","params","publicKey","tokenFromUri","cookieAuthResult","authResponse"]}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/provider.tsx"],"sourcesContent":["import { json } from \"@remix-run/node\";\n\nimport { parseCookies, validateAndParsePublicKey, fetchUserData } from \"@authdog/node-commons\";\n\n// Function to create authentication response with cookies\nexport const createAuthResponse = (\n authenticatedUser: any,\n token: string,\n environmentId: string,\n request: Request,\n) => {\n // Create response with cookies\n const response = json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n });\n\n // Set cookies in the response headers\n const headers = new Headers(response.headers);\n\n // Serialize the user object separately\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n const userSessionHashValue = token;\n\n headers.append(\n \"Set-Cookie\",\n `user_session_${environmentId}=${encodeURIComponent(userSessionValue)}; Path=/; HttpOnly; Secure; SameSite=Strict`,\n );\n headers.append(\n \"Set-Cookie\",\n `user_session_hash_${environmentId}=${encodeURIComponent(userSessionHashValue)}; Path=/; HttpOnly; Secure; SameSite=Strict`,\n );\n\n // Add cache control headers\n headers.append(\n \"Cache-Control\",\n \"no-store, no-cache, must-revalidate, proxy-revalidate\",\n );\n headers.append(\"Pragma\", \"no-cache\");\n headers.append(\"Expires\", \"0\");\n headers.append(\"Vary\", \"Cookie\");\n headers.append(\"Content-Type\", \"application/json\");\n headers.append(\"Access-Control-Allow-Origin\", \"*\");\n headers.append(\"Access-Control-Allow-Credentials\", \"true\");\n\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n },\n {\n headers,\n },\n );\n};\n\n// Function to authenticate with cookies\nexport const authenticateWithCookies = async (\n request: Request,\n publicKeyObj: any,\n) => {\n try {\n // Get cookies from request\n const cookieHeader = request.headers.get(\"Cookie\");\n const cookies = parseCookies(cookieHeader);\n\n if (cookies.length === 0) {\n return json({\n user: null,\n isAuthenticated: false,\n });\n }\n\n // Find our specific cookies\n const userSessionHashCookie = cookies.find(\n (c: any) => c.name === `user_session_hash_${publicKeyObj?.environmentId}`,\n );\n\n if (userSessionHashCookie) {\n const userSessionHashValue = userSessionHashCookie.value;\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n userSessionHashValue,\n );\n\n return json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n });\n }\n } catch (error) {\n console.error(\"Error authenticating with cookies:\", error);\n }\n\n return null;\n};\n\n// Main loader function\nexport const remixAuthLoader = async ({\n request,\n context,\n params\n}: {\n request: Request;\n context: Record<string, any>;\n params: any;\n}) => {\n const publicKey = typeof process !== \"undefined\" ? process.env.PK_AUTHDOG as string\n : params?.publicKey;\n const publicKeyObj = validateAndParsePublicKey(publicKey);\n\n // First check if we have a token in the URL\n const url = new URL(request.url);\n const tokenFromUri = url.searchParams.get(\"token\");\n\n // Try to authenticate using cookies first\n const cookieAuthResult = await authenticateWithCookies(\n request,\n publicKeyObj,\n );\n \n if (cookieAuthResult) {\n // If we have a token in URL, still process it but don't show loading\n if (tokenFromUri) {\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n tokenFromUri,\n );\n\n if (authenticatedUser?.meta && authenticatedUser?.meta?.code === 200) {\n // Store in context for later use\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n context[`user_session_${publicKeyObj?.environmentId}`] = userSessionValue;\n context[`user_session_hash_${publicKeyObj?.environmentId}`] = tokenFromUri;\n\n // Create the response with auth data\n const authResponse = createAuthResponse(\n authenticatedUser,\n tokenFromUri,\n publicKeyObj?.environmentId,\n request,\n );\n\n // Return the response with cookies but don't redirect\n // The client-side reload will handle the URL cleanup\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n },\n {\n headers: authResponse.headers,\n }\n );\n }\n }\n return cookieAuthResult;\n }\n\n // If we have a token but no cookie auth, show loading while processing token\n if (tokenFromUri) {\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n tokenFromUri,\n );\n\n if (authenticatedUser?.meta && authenticatedUser?.meta?.code === 200) {\n // Store in context for later use\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n context[`user_session_${publicKeyObj?.environmentId}`] = userSessionValue;\n context[`user_session_hash_${publicKeyObj?.environmentId}`] = tokenFromUri;\n\n // Create the response with auth data\n const authResponse = createAuthResponse(\n authenticatedUser,\n tokenFromUri,\n publicKeyObj?.environmentId,\n request,\n );\n\n // Return the response with cookies but don't redirect\n // The client-side reload will handle the URL cleanup\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n },\n {\n headers: authResponse.headers,\n }\n );\n }\n return json({ loading: true });\n }\n\n // If we get here, we're not authenticated and not loading\n return json({\n user: null,\n isAuthenticated: false,\n });\n};\n\nexport {AuthdogProvider} from \"./provider.tsx\"","\"use client\";\nimport React, { useEffect, useState } from \"react\";\n\nexport const AuthdogProvider = ({ children }: { children: React.ReactNode }) => {\n const [isLoading, setIsLoading] = useState(true);\n\n useEffect(() => {\n // Check if we're in the browser\n if (typeof window !== 'undefined') {\n // Check if there's a token in the URL\n const url = new URL(window.location.href);\n const token = url.searchParams.get(\"token\");\n \n if (token) {\n // Remove token from URL without triggering a page reload\n url.searchParams.delete(\"token\");\n window.history.replaceState({}, document.title, url.toString());\n \n // Force a reload to ensure the server processes the token\n window.location.reload();\n return;\n }\n \n // If no token, we're done loading\n setIsLoading(false);\n }\n }, []);\n\n // Show nothing while loading\n if (isLoading) {\n return null;\n }\n\n return <>{children}</>;\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Q,qBAAqBT,GAAc,aAAa,EAAE,EAAIa,EAG9D,IAAME,EAAe1B,EACnBC,EACAuB,EACAb,GAAc,cACdP,CACF,EAIA,OAAOE,EACL,CACE,KAAML,EAAkB,KACxB,gBAAiB,EACnB,EACA,CACE,QAASyB,EAAa,OACxB,CACF,CACF,CACF,CACA,OAAOD,CACT,CAGA,GAAID,EAAc,CAChB,IAAMvB,EAAoB,MAAMgB,EAC9BN,GAAc,aACdA,GAAc,cACda,CACF,EAEA,GAAIvB,GAAmB,MAAQA,GAAmB,MAAM,OAAS,IAAK,CAEpE,IAAMO,EAAmB,KAAK,UAAUP,GAAmB,IAAI,EAC/DmB,EAAQ,gBAAgBT,GAAc,aAAa,EAAE,EAAIH,EACzDY,EAAQ,qBAAqBT,GAAc,aAAa,EAAE,EAAIa,EAG9D,IAAME,EAAe1B,EACnBC,EACAuB,EACAb,GAAc,cACdP,CACF,EAIA,OAAOE,EACL,CACE,KAAML,EAAkB,KACxB,gBAAiB,EACnB,EACA,CACE,QAASyB,EAAa,OACxB,CACF,CACF,CACA,OAAOpB,EAAK,CAAE,QAAS,EAAK,CAAC,CAC/B,CAGA,OAAOA,EAAK,CACV,KAAM,KACN,gBAAiB,EACnB,CAAC,CACH","names":["json","parseCookies","validateAndParsePublicKey","fetchUserData","useEffect","useState","Fragment","jsx","AuthdogProvider","children","isLoading","setIsLoading","url","createAuthResponse","authenticatedUser","token","environmentId","request","response","json","headers","userSessionValue","userSessionHashValue","authenticateWithCookies","publicKeyObj","cookieHeader","cookies","parseCookies","userSessionHashCookie","c","fetchUserData","error","remixAuthLoader","context","params","publicKey","validateAndParsePublicKey","tokenFromUri","cookieAuthResult","authResponse"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/provider.tsx"],"sourcesContent":["import { json } from \"@remix-run/node\";\n\nimport {\n parseCookies,\n validateAndParsePublicKey,\n fetchUserData,\n} from \"@authdog/node-commons\";\n\n// Function to create authentication response with cookies\nexport const createAuthResponse = (\n authenticatedUser: any,\n token: string,\n environmentId: string,\n request: Request,\n) => {\n // Create response with cookies\n const response = json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n });\n\n // Set cookies in the response headers\n const headers = new Headers(response.headers);\n\n // Serialize the user object separately\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n const userSessionHashValue = token;\n\n headers.append(\n \"Set-Cookie\",\n `user_session_${environmentId}=${encodeURIComponent(userSessionValue)}; Path=/; HttpOnly; Secure; SameSite=Strict`,\n );\n headers.append(\n \"Set-Cookie\",\n `user_session_hash_${environmentId}=${encodeURIComponent(userSessionHashValue)}; Path=/; HttpOnly; Secure; SameSite=Strict`,\n );\n\n // Add cache control headers\n headers.append(\n \"Cache-Control\",\n \"no-store, no-cache, must-revalidate, proxy-revalidate\",\n );\n headers.append(\"Pragma\", \"no-cache\");\n headers.append(\"Expires\", \"0\");\n headers.append(\"Vary\", \"Cookie\");\n headers.append(\"Content-Type\", \"application/json\");\n headers.append(\"Access-Control-Allow-Origin\", \"*\");\n headers.append(\"Access-Control-Allow-Credentials\", \"true\");\n\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n },\n {\n headers,\n },\n );\n};\n\n// Function to authenticate with cookies\nexport const authenticateWithCookies = async (\n request: Request,\n publicKeyObj: any,\n) => {\n try {\n // Get cookies from request\n const cookieHeader = request.headers.get(\"Cookie\");\n const cookies = parseCookies(cookieHeader);\n\n if (cookies.length === 0) {\n return json({\n user: null,\n isAuthenticated: false,\n });\n }\n\n // Find our specific cookies\n const userSessionHashCookie = cookies.find(\n (c: any) => c.name === `user_session_hash_${publicKeyObj?.environmentId}`,\n );\n\n if (userSessionHashCookie) {\n const userSessionHashValue = userSessionHashCookie.value;\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n userSessionHashValue,\n );\n\n return json({\n user: authenticatedUser.user,\n isAuthenticated: true,\n });\n }\n } catch (error) {\n console.error(\"Error authenticating with cookies:\", error);\n }\n\n return null;\n};\n\n// Main loader function\nexport const remixAuthLoader = async ({\n request,\n context,\n params,\n}: {\n request: Request;\n context: Record<string, any>;\n params: any;\n}) => {\n const publicKey =\n typeof process !== \"undefined\"\n ? (process.env.PK_AUTHDOG as string)\n : params?.publicKey;\n const publicKeyObj = validateAndParsePublicKey(publicKey);\n\n // First check if we have a token in the URL\n const url = new URL(request.url);\n const tokenFromUri = url.searchParams.get(\"token\");\n\n // Try to authenticate using cookies first\n const cookieAuthResult = await authenticateWithCookies(request, publicKeyObj);\n\n if (cookieAuthResult) {\n // If we have a token in URL, still process it but don't show loading\n if (tokenFromUri) {\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n tokenFromUri,\n );\n\n if (authenticatedUser?.meta && authenticatedUser?.meta?.code === 200) {\n // Store in context for later use\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n context[`user_session_${publicKeyObj?.environmentId}`] =\n 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 the response with cookies but don't redirect\n // The client-side reload will handle the URL cleanup\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n },\n {\n headers: authResponse.headers,\n },\n );\n }\n }\n return cookieAuthResult;\n }\n\n // If we have a token but no cookie auth, show loading while processing token\n if (tokenFromUri) {\n const authenticatedUser = await fetchUserData(\n publicKeyObj?.identityHost,\n publicKeyObj?.environmentId,\n tokenFromUri,\n );\n\n if (authenticatedUser?.meta && authenticatedUser?.meta?.code === 200) {\n // Store in context for later use\n const userSessionValue = JSON.stringify(authenticatedUser?.user);\n context[`user_session_${publicKeyObj?.environmentId}`] = userSessionValue;\n context[`user_session_hash_${publicKeyObj?.environmentId}`] =\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 the response with cookies but don't redirect\n // The client-side reload will handle the URL cleanup\n return json(\n {\n user: authenticatedUser.user,\n isAuthenticated: true,\n },\n {\n headers: authResponse.headers,\n },\n );\n }\n return json({ loading: true });\n }\n\n // If we get here, we're not authenticated and not loading\n return json({\n user: null,\n isAuthenticated: false,\n });\n};\n\nexport { AuthdogProvider } from \"./provider.tsx\";\n","\"use client\";\nimport React, { useEffect, useState } from \"react\";\n\nexport const AuthdogProvider = ({\n children,\n}: {\n children: React.ReactNode;\n}) => {\n const [isLoading, setIsLoading] = useState(true);\n\n useEffect(() => {\n // Check if we're in the browser\n if (typeof window !== \"undefined\") {\n // Check if there's a token in the URL\n const url = new URL(window.location.href);\n const token = url.searchParams.get(\"token\");\n\n if (token) {\n // Remove token from URL without triggering a page reload\n url.searchParams.delete(\"token\");\n window.history.replaceState({}, document.title, url.toString());\n\n // Force a reload to ensure the server processes the token\n window.location.reload();\n return;\n }\n\n // If no token, we're done loading\n setIsLoading(false);\n }\n }, []);\n\n // Show nothing while loading\n if (isLoading) {\n return null;\n }\n\n return <>{children}</>;\n};\n"],"mappings":"AAAA,OAAS,QAAAA,MAAY,kBAErB,OACE,gBAAAC,EACA,6BAAAC,EACA,iBAAAC,MACK,wBCLP,OAAgB,aAAAC,EAAW,YAAAC,MAAgB,QAoClC,mBAAAC,EAAA,OAAAC,MAAA,oBAlCF,IAAMC,EAAkB,CAAC,CAC9B,SAAAC,CACF,IAEM,CACJ,GAAM,CAACC,EAAWC,CAAY,EAAIN,EAAS,EAAI,EAyB/C,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,E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GAAc,cACdP,CACF,EAIA,OAAOE,EACL,CACE,KAAML,EAAkB,KACxB,gBAAiB,EACnB,EACA,CACE,QAASyB,EAAa,OACxB,CACF,CACF,CACA,OAAOpB,EAAK,CAAE,QAAS,EAAK,CAAC,CAC/B,CAGA,OAAOA,EAAK,CACV,KAAM,KACN,gBAAiB,EACnB,CAAC,CACH","names":["json","parseCookies","validateAndParsePublicKey","fetchUserData","useEffect","useState","Fragment","jsx","AuthdogProvider","children","isLoading","setIsLoading","url","createAuthResponse","authenticatedUser","token","environmentId","request","response","json","headers","userSessionValue","userSessionHashValue","authenticateWithCookies","publicKeyObj","cookieHeader","cookies","parseCookies","userSessionHashCookie","c","fetchUserData","error","remixAuthLoader","context","params","publicKey","validateAndParsePublicKey","tokenFromUri","cookieAuthResult","authResponse"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authdog/remix-node",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Authdog Remix SDK",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@remix-run/node": "^2.15.2",
|
|
25
25
|
"@remix-run/react": "^2.16.5",
|
|
26
26
|
"react": "^18.2.0",
|
|
27
|
-
"@authdog/node-commons": "0.0.
|
|
27
|
+
"@authdog/node-commons": "0.0.21"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^22.14.1",
|