Skip to content

Commit

Permalink
fix: passing correct env based on runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
hambergerpls committed Oct 23, 2024
1 parent 4fe2e43 commit d41966e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
14 changes: 9 additions & 5 deletions src/cloudflare/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
* ```
*
*
* @module auth-remix
* @module auth-remix/cloudflare
*/

import {
Expand Down Expand Up @@ -208,7 +208,8 @@ export function RemixAuth(config: RemixAuthConfig) {
"csrf",
request.headers.get("x-forwarded-proto") ?? new URL( request.url ).protocol,
request.headers,
process.env,
// @ts-expect-error
context.cloudflare.env,
config
)

Expand All @@ -232,7 +233,8 @@ export function RemixAuth(config: RemixAuthConfig) {
"session",
request.headers.get("x-forwarded-proto") ?? new URL( request.url ).protocol,
request.headers,
process.env,
// @ts-expect-error
context.cloudflare.env,
config
)

Expand Down Expand Up @@ -269,7 +271,8 @@ export function RemixAuth(config: RemixAuthConfig) {
"signin",
headers.get("x-forwarded-proto") ?? new URL( request.url ).protocol,
headers,
process.env,
// @ts-expect-error
context.cloudflare.env,
config
)

Expand Down Expand Up @@ -326,7 +329,8 @@ authorizationParams
"signout",
headers.get("x-forwarded-proto") ?? new URL( request.url ).protocol,
headers,
process.env,
// @ts-expect-error
context.cloudflare.env,
config
)
const callbackUrl = options?.redirectTo ?? headers.get("Referer") ?? "/"
Expand Down
14 changes: 9 additions & 5 deletions src/deno/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
* ```
*
*
* @module auth-remix
* @module auth-remix/deno
*/

import {
Expand Down Expand Up @@ -208,7 +208,8 @@ export function RemixAuth(config: RemixAuthConfig) {
"csrf",
request.headers.get("x-forwarded-proto") ?? new URL( request.url ).protocol,
request.headers,
process.env,
// @ts-expect-error
Deno.env.toObject(),
config
)

Expand All @@ -232,7 +233,8 @@ export function RemixAuth(config: RemixAuthConfig) {
"session",
request.headers.get("x-forwarded-proto") ?? new URL( request.url ).protocol,
request.headers,
process.env,
// @ts-expect-error
Deno.env.toObject(),
config
)

Expand Down Expand Up @@ -269,7 +271,8 @@ export function RemixAuth(config: RemixAuthConfig) {
"signin",
headers.get("x-forwarded-proto") ?? new URL( request.url ).protocol,
headers,
process.env,
// @ts-expect-error
Deno.env.toObject(),
config
)

Expand Down Expand Up @@ -326,7 +329,8 @@ authorizationParams
"signout",
headers.get("x-forwarded-proto") ?? new URL( request.url ).protocol,
headers,
process.env,
// @ts-expect-error
Deno.env.toObject(),
config
)
const callbackUrl = options?.redirectTo ?? headers.get("Referer") ?? "/"
Expand Down
8 changes: 1 addition & 7 deletions src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
* ```
*
*
* @module auth-remix
* @module auth-remix/node
*/

import {
Expand Down Expand Up @@ -186,14 +186,12 @@ export type RemixAuthConfig = Omit<AuthConfig, "raw">

export function RemixAuth(config: RemixAuthConfig) {
const loader: LoaderFunction = async ({ request, params, context }) => {
// @ts-expect-error
setEnvDefaults(process.env, config)
config.basePath = getBasePath({ request, params })
return await Auth(request, config)
}

const action: ActionFunction = async ({ request, params, context }) => {
// @ts-expect-error
setEnvDefaults(process.env, config)
config.basePath = getBasePath({ request, params })
return await Auth(request, config)
Expand All @@ -202,7 +200,6 @@ export function RemixAuth(config: RemixAuthConfig) {
const getCsrfToken = async (
{ request, context }: Omit< LoaderFunctionArgs | ActionFunctionArgs, "params" >,
): Promise<Response> => {
// @ts-expect-error
setEnvDefaults(process.env, config)
const url = createActionURL(
"csrf",
Expand All @@ -226,7 +223,6 @@ export function RemixAuth(config: RemixAuthConfig) {
const getSession = async (
{ request, context }: Omit< LoaderFunctionArgs | ActionFunctionArgs, "params" >,
): GetSessionResult => {
// @ts-expect-error
setEnvDefaults(process.env, config)
const url = createActionURL(
"session",
Expand Down Expand Up @@ -257,7 +253,6 @@ export function RemixAuth(config: RemixAuthConfig) {
options: ({ redirectTo?: string }) = {},
authorizationParams?: string[][] | Record<string, string> | string | URLSearchParams,
) => {
// @ts-expect-error
setEnvDefaults(process.env, config)
const headers = new Headers(request.headers)
const {
Expand Down Expand Up @@ -317,7 +312,6 @@ authorizationParams
{ request, context }: Omit< LoaderFunctionArgs | ActionFunctionArgs, "params" >,
options: { redirectTo?: string } = {},
) => {
// @ts-expect-error
setEnvDefaults(process.env, config)
const headers = new Headers( request.headers )
headers.set("Content-Type", "application/x-www-form-urlencoded")
Expand Down

0 comments on commit d41966e

Please sign in to comment.