diff --git a/packages/auth-providers/dbAuth/api/src/shared.ts b/packages/auth-providers/dbAuth/api/src/shared.ts index 552833411a36..ced1e85f6a04 100644 --- a/packages/auth-providers/dbAuth/api/src/shared.ts +++ b/packages/auth-providers/dbAuth/api/src/shared.ts @@ -1,7 +1,7 @@ import type { APIGatewayProxyEvent } from 'aws-lambda' import CryptoJS from 'crypto-js' -import { getConfig } from '@redwoodjs/project-config' +import { getConfig, getConfigPath } from '@redwoodjs/project-config' import * as DbAuthError from './errors' @@ -125,8 +125,21 @@ export const hashPassword = (text: string, salt?: string) => { } export const cookieName = (name: string | undefined) => { - const port = getConfig().api?.port || 8911 + const port = getPort() const cookieName = name?.replace('%port%', '' + port) ?? 'session' return cookieName } + +function getPort() { + let configPath + + try { + configPath = getConfigPath() + } catch { + // If this throws, we're in a serverless environment, and the `redwood.toml` file doesn't exist. + return 8911 + } + + return getConfig(configPath).api.port +}